![]() |
PCDVD數位科技討論區
(https://www.pcdvd.com.tw/index.php)
- 七嘴八舌異言堂
(https://www.pcdvd.com.tw/forumdisplay.php?f=12)
- - [請益]請教一個shell script使用上的問題
(https://www.pcdvd.com.tw/showthread.php?t=1056660)
|
---|
[請益]請教一個shell script使用上的問題
假設scrip的內容是如下
--------------------------------------------------------- #!/bin/sh name="We Have Overcome (HM27 1989)" rarachive=` sed -n 1p test.txt ` --------------------------------------------------------- 假設txt文件的內容如下行 --------------------------------------------------------- rar a -m0 -hp123456789 -v90960b -rr3 -ep1 test.rar "$name" --------------------------------------------------------- 請問有沒有辦法從shell script裡面直接調用rarachive取得的文字(如上rar a -m0 -hp123456789 -v90960b -rr3 -ep1 test.rar "$name")當作command line來執行,且command line中的$name需要由shell script中得自定義變數(如上"We Have Overcome (HM27 1989)")來取得 請教大家:) |
直接在script裡面,直接執行另一個script,
同時帶參數或管線,應該可以吧? |
rarachive 寫成function不就好了?
shell只要帶rarachive.sh rarachive 就可以執行了阿,你要帶啥參數就帶啥 不過如果參數中有空白就要小心 #!/bin/sh function archive(){ rarachive=$(sed -n 1p test.txt) } name="We Have Overcome (HM27 1989)" if [ $# -ne 0 ];then for opt in ${@};do cmd="$cmd ${opt}" done $cmd fi |
還是你要這個?
. ./xxxx.sh 這樣你的參數會被帶進去當下的環境喔 .等同source,效果一樣 記得~~你的script內不可以下exit 如果硬要做"離開動作時",要用kill -INT $$ |
所有的時間均為GMT +8。 現在的時間是10:09 PM. |
vBulletin Version 3.0.1
powered_by_vbulletin 2025。