shell腳本
In the command line, a shell script is an executable file that contains a set of instructions that the shell will execute. Its main purpose is to reduce a set of instructions (or commands) in just one file. Also it can handle some logic because it’s a programming language.
在命令行中,shell腳本是一個可執行文件,其中包含該Shell將執行的一組指令。 它的主要目的是減少一個文件中的一組指令(或命令)。 由于它是一種編程語言,因此它還可以處理一些邏輯。
如何建立 (How to create it)
Create the file:
創建文件:
$ touch myscript.sh
Add a shebang at the start of the file. The Shebang line is responsible for letting the command interpreter know which interpreter the shell script will be run with:
在文件的開頭添加一個Shebang 。 Shebang行負責讓命令解釋器知道將運行shell腳本的解釋器:
$ echo "#!/bin/bash" > myscript.sh
# or
$ your-desired-editor myscript.sh
# write at the first line #!/bin/bash
Add some commands:
添加一些命令:
$ echo "echo Hello World!" >> myscript.sh
Give the file execution mode:
給出文件執行方式:
$ chmod +x myscript.sh
Execute it!
執行它!
$ ./myscript.sh
Hello World!
More info about shell-scripting can be found here
有關shell腳本的更多信息,請參見此處。
有關Shell腳本和Linux的更多信息: (More info on shell scripting and Linux:)
A beginner's guide to surviving in the Linux shell
在Linux Shell中生存的初學者指南
Basic Linux commands to know
基本的Linux命令要知道
Shell scripting tricks
Shell腳本技巧
翻譯自: https://www.freecodecamp.org/news/shell-scripting/
shell腳本