shell command line argument + parsing function

Stefan Miklosovic miklosovic.freebsd at gmail.com
Sun Aug 30 23:18:47 UTC 2009


hehe :D

easy as hell, one has to enclose argument of parse_cmdline into brackets :)

parse_cmdline "$@"

sorry for noise

On Mon, Aug 31, 2009 at 1:07 AM, Stefan Miklosovic <
miklosovic.freebsd at gmail.com> wrote:

> 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
>


More information about the freebsd-questions mailing list