freeCodeCamp/guide/chinese/linux/shell-scripting/index.md

992 B
Raw Blame History

title localeTitle
Shell scripting Shell脚本

Shell脚本

在命令行中shell脚本是包含集合的可执行文件 shell将执行的指令。它的主要目的是减少 只有一个文件中的一组指令(或命令)。它也可以处理 一些逻辑,因为它是一种编程语言。

如何创建它

1创建文件

$ touch myscript.sh 

2在文件的开头添加一个shebang 。 Shebang行负责让命令解释器知道将运行shell脚本的解释器

$ echo "#!/bin/bash" > myscript.sh 
 # or 
 $ your-desired-editor myscript.sh 
 # write at the first line #!/bin/bash 

3添加一些命令

$ echo "echo Hello World!" >> myscript.sh 

4给出文件_执行_模式

$ chmod +x myscript.sh 

5执行它

$ ./myscript.sh 
 Hello World! 

有关shell-scripting的更多信息访问此处