![]() Consult our guide to file locations in Windows 10’s Bash shell for more details. For example, if you wanted to specify the C:\Users\Bob\Downloads\test.txt file, you’d need to specify the /mnt/c/Users/Bob/Downloads/test.txt path. To access Windows files in the script, you’ll need to specify their path under /mnt/c, not their Windows path. 如何在Bash脚本中使用Windows文件 (How to Work With Windows Files in a Bash Script ) If you’re using the Nano text editor, you can save the file by pressing Ctrl O and then Enter. # print the contents of the variable on screen You’re restricted to Linux terminal commands and utilities, just as you would be on a typical Linux system. ![]() Note that there’s no way to run Windows programs from within the Bash environment. The same techniques will work in Bash on Ubuntu on Windows. For more advanced tricks, consult a more detailed guide to Bash scripts on Linux. Add a “#” character before a line to treat it as a “comment”, something which helps you and other people understand the script but which isn’t run as a command. The script will run each command in turn. However, you can use more advanced text editors–for example, Notepad allows you to give a file UNIX end-of-line characters by clicking Edit > EOL Conversion > UNIX/OSX Format. Save the file in Notepad and it won’t be interpreted properly by Bash. In other words, this means that you can’t simply write a shell script in Notepad. ![]() When writing shell scripts on Windows, bear in mind that Windows and UNIX-like systems like Linux use different “end of line” characters in text files in shell scripts. ![]() Windows and UNIX use different end-of-line characters, and the Windows file system is accessible in a different location in the Bash environment. 随着 Windows 10 Bash Shell的到来,您现在可以在Windows 10上创建并运行Bash Shell脚本。您还可以将Bash命令合并到Windows批处理文件或PowerShell脚本中。Įven if you know what you’re doing, this isn’t necessarily as simple as it seems. You can also incorporate Bash commands into a Windows batch file or PowerShell script. With the arrival of Windows 10’s Bash shell, you can now create and run Bash shell scripts on Windows 10.
0 Comments
Leave a Reply. |