shell script -- getopt 問題 - Linux

Table of Contents


getopt要如何正確處理含有空白的arg?
以下是小弟的script

test.sh
#!/bin/bash

args=`getopt a:b: $*`
if [ $? -ne 0 ]; then
echo error
exit 1
fi

set -- $args

while true
do
case "$1" in
-a)
a="$2"
shift 2
;;
-b)
b="$2"
shift 2
;;
--)
shift
break
;;
*)
echo error
exit 2
;;
esac
done


echo $a
echo $b


執行結果
# ./test2.sh -a AAA -b BBB
AAA
BBB
正常


但是
# ./test2.sh -a "AAA AAA" -b "BBB BBB"
並不會輸出我想要的結果
AAA AAA
BBB BBB


不知要怎麼寫才能正常處理空白



--

All Comments