shell script -- getopt 問題 - Linux

By Kelly
at 2008-08-09T20:09
at 2008-08-09T20:09
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
不知要怎麼寫才能正常處理空白
--
Tags:
Linux
All Comments
Related Posts
samba的設定

By Daniel
at 2008-08-09T19:29
at 2008-08-09T19:29
用了ubuntu8.04和lazyubuntu 我流淚了

By Catherine
at 2008-08-09T19:13
at 2008-08-09T19:13
Re: PCManX GTK+ 0.3.8 釋出

By Lauren
at 2008-08-09T18:59
at 2008-08-09T18:59
安裝ubuntu

By Selena
at 2008-08-09T15:27
at 2008-08-09T15:27
更新玩後sudo nautilus不能使用了??

By Gary
at 2008-08-08T22:40
at 2008-08-08T22:40