歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> 第一個shell程序:hello world

第一個shell程序:hello world

日期:2017/3/1 10:11:01   编辑:SHELL編程

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

  1. [root@localhost Desktop]# mkdir think
  2. [root@localhost Desktop]# ls
  3. think
  4. [root@localhost Desktop]# cd think
  5. [root@localhost think]# vim shell01.sh

  1. #! /bin/bash
  2. #program:
  3. #the program is for outputting "hello world"
  4. #history:
  5. #date 2012/9/5 autor think version 1st
  6. PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
  7. #begin program
  8. echo -e "hello\fworld \n"
  9. exit 1
  10. [root@localhost think]# chmod +rx shell01.sh
  11. [root@localhost think]# ./shell01.sh
  12. hello
  13. world
  14. [root@localhost think]# echo $?
  15. 1
Copyright © Linux教程網 All Rights Reserved