Date: Mon, 31 Aug 2009 01:07:36 +0200 From: Stefan Miklosovic <miklosovic.freebsd@gmail.com> To: freebsd-questions@freebsd.org Subject: shell command line argument + parsing function Message-ID: <f99a79ec0908301607l7772a486j1986b87d31d33cef@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
hi,
assuming I execute shell script like this
$ ./script -c "hello world"
I want to save "hello world" string to variable COMMENT in shell script.
code:
#!/bin/sh
parse_cmdline() {
while [ $# -gt 0 ]; do
case "$1" in
-c)
shift
COMMENT="$1"
;;
esac
shift
done
}
parse_cmdline $*
echo $COMMENT
exit 0
but that only write out "hello". I tried to change $* to $@, nothing
changed.
It is interesting, that if I dont put "while" loop into function
parse_cmdline,
and do echo $COMMENT, it writes "hello world".
I WANT that function style. How to do it ?
thank you
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?f99a79ec0908301607l7772a486j1986b87d31d33cef>
