Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 31 Aug 2009 01:18:43 +0200
From:      Stefan Miklosovic <miklosovic.freebsd@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: shell command line argument + parsing function
Message-ID:  <f99a79ec0908301618j26a25a21j9c8128f1edcca06f@mail.gmail.com>
In-Reply-To: <f99a79ec0908301607l7772a486j1986b87d31d33cef@mail.gmail.com>
References:  <f99a79ec0908301607l7772a486j1986b87d31d33cef@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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@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
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?f99a79ec0908301618j26a25a21j9c8128f1edcca06f>