1 shell script必須具備可讀與可執行(rx)的權限。
2 script的執行方式的區別:
1)sh script_name或./script_name:在子進程中執行(一個新的bash環境)
2)source script_name:在父進程中執行
【提示】當子進程完成後,子進程內的各項變量或者操作將會結束而不會傳回到父進程中
3 script的編程習慣
1)程序的內容說明:script的用途、作者、建立日期等
2)主要環境變量的聲明:如,PATH、LANG等
3)適當的地方作注釋
4)2/4縮進
4 hello world
- [root@localhost Desktop]# mkdir think
- [root@localhost Desktop]# ls
- think
- [root@localhost Desktop]# cd think
- [root@localhost think]# vim shell01.sh
- #! /bin/bash
- #program:
- #the program is for outputting "hello world"
- #history:
- #date 2012/9/5 autor think version 1st
- PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
- #begin program
- echo -e "hello\fworld \n"
- exit 1
- [root@localhost think]# chmod +rx shell01.sh
- [root@localhost think]# ./shell01.sh
- hello
- world
-
- [root@localhost think]# echo $?
- 1