0
在我的shell腳本中,我正在讀取兩個可選參數。 第一個參數沒有被讀取。下面給出的是代碼:Sh shell腳本可選參數未讀取
#! /bin/sh
while getopts "f:c:" opt;
do
case "${opt}" in
f) file=${OPTARG}
echo "" "File Name: ${file}"
;;
c) str=${OPTARG}
echo "" "String: ${str}"
;;
esac
done
當我運行我的腳本:
$ sh myscript.sh -f filename.txt -c someString
輸出:
$ File Name:
$ String: someString
請讓我知道我要去哪裏錯了。 我已經嘗試了所有選項getopts的:
:f:c
f:c
f:c:
:f:c:
海峽= $ {} OPTAGR應海峽= {} OPTARG哦 – Jdamian 2014-10-11 10:39:33
我似乎有誤此處鍵入它..:P碼具有海峽= $ {} OPTARG – aiman 2014-10-11 10:43:37
謝謝Jdamian:D ..typo錯誤殺了我:P – aiman 2014-10-11 10:46:55