方法有三種:bash
1 使用sourcespa
2 使用 .file
3 使用sh方法
簡單實驗:腳本
first.shco
#!/bin/bash
echo 'your are in first file'參數傳遞
second.shbackground
#!/bin/bash
echo 'your are in second file'參數
source first.sh // . first.sh // sh first.shab
執行結果:
your are in second file
your are in first file
如今討論關於參數傳遞:
first.sh
#!/bin/bash
echo 'your are in first file'
echo "${0} ${1}"
second.sh
#!/bin/bash
echo 'your are in second file'
echo "${0} ${1}"
. first.sh ${2} //source first.sh
執行:./second.sh abc 123
your are in second file
./second.sh abc
your are in first file
./second.sh 123
改變second.sh
second.sh
#!/bin/bash
echo 'your are in second file'
echo "${0} ${1}"
sh first.sh ${2}
執行:
./second.sh abc 123
結果:
your are in second file
./second.sh abc
your are in first file
first.sh 123
因此在調用的那個腳本須要傳遞參數的時候仍是要注意選對方法的