bash-like arrays with busybox / ash

Roy Marples roy at marples.name
Thu Mar 12 15:56:54 UTC 2009


Guenter wrote:
> Here's what I have now, and this works basically, though still need to
> understand the set construct:

set -- one two three
Sets the position parameters $1 $2 and $3 to one two three respectively

set -- "hello world" foo bar
$1="hello world"
$2=foo
$3=bar

somefunc()
{
      echo $1
      echo $2
      echo $3
}

somefunc "hello world" foo bar

HTH


> one thing I didnt find yet in any docu: how can I catch if a string is
> entered instead of a number with read?

if ! printf "%d" $n >/dev/null 2>&1; then
    echo "You didn't enter a number"
    exit 1
fi

> Also if there's still a better / shorter way to do the same I would love
> to hear about!

Many ways to skin a cat. If it works for you then great!

Thanks

Roy


More information about the busybox mailing list