爲了運行bash腳本我需要一些參數和標誌,因爲需求是相當棘手,我選擇使用getopt的功能這樣 while getopts ":s:g:r" o; do
case "${o}" in
s)
# Variables that require value
VALUE1=${OPTARG}
;;
g)
# Varia
的下面while循環我的一個殼中存在稱作test.sh 我想運行下面的命令 ksh的-x test.sh -c -e文件1文件2 我想while循環的循環中執行這兩個C)情況下,第一則E)的情況下,但目前它只是在執行C)的情況下 有人能告訴我如何得到它來執行都?第一批C類),那麼E) while getopts ":c:e:" opt; do
case $opt in
c)
我試圖使用getopts的是這樣的: #!/bin/bash
while getopts "i" option
do
case "${option}"
in
i) INT=${OPTARG};;
esac
done
echo "$INT"
但它打印$ INT只有當我使用getopts "i:"。如果我理解正確,optstring中的冒號表示相應標誌需要值。但是我想讓這個標誌可
我想重新實現我自己的getopts(如果可能,請在python中)。 我的問題是,我不明白這是怎麼可能的: # The call of the following script
./script -h
#!/bin/bash
getopts 'h' TEST # output nothing
echo $TEST # output h
env | grep # output noth
如果getopts中提供了多個選項並且一些需要參數而有些不需要參數,會怎麼樣? getopts的參數挑選下一個參數作爲參數 #!/bin/bash
while getopts ":a:b:cde:f:g:" opt; do
case $opt in
a)
echo "-a was triggered, Parameter: $OPTARG" >&2
;;
我想弄清楚如何傳遞逗號分隔的列表作爲輸入,並讓我的函數一次處理一個值。 我的功能: addToWhitelist()
{
host='127.0.0.1'
db='mytest'
_mongo=$(which mongo);
echo "${_ip}";
read -a arr <<<${_ip};
for i in ${arr[@]}
我一直在學習命令行參數解析。有長的絲這個了,我並不想在這裏挑起一個: Using getopts in bash shell script to get long and short command line options How do I parse command line arguments in Bash? 使用getopts的,如果你想分析的參數/值對,如「--opt值「,一種方法是讓