2015年7月17日 星期五

script 的執行方式差異 (source, sh script, ./script)

http://linux.vbird.org/linux_basic/0340bashshell-scripts.php

##### [ demo01.sh
#!/bin/bash
# Program:
#    User inputs his first name and last name.  Program shows his full name.
# History:
# 2005/08/23    VBird    First release
# 2015/07/16    Yulin    Modified for demo of different script execution ways.

read -p "Please input your first name: " firstname  # 提示使用者輸入
read -p "Please input your last name:  " lastname   # 提示使用者輸入
echo -e "\nYour full name is: $firstname $lastname" # 結果由螢幕輸出
##### ] demo01.sh

$source demo01.sh
$. demo01.sh
==> both the above 2 ways alter the environment of the parent process.

#sh demo01.sh
#./demo01.sh
==> both the above 2 ways create a child process to carry out the script and won't alter the environment of the parent process.

沒有留言: