[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: quoting variable names in shell scripts



* 2011-07-07T07:13:24+02:00 * Javier Barroso wrote:

> On Thu, Jul 7, 2011 at 5:22 AM, Kamaraju S Kusumanchi
> <raju.mailinglists@gmail.com> wrote:
>> Consider the following shell script

>> #! /bin/sh

> You can use array variables if you want:
>
> names=("kama" "raju" "k a m a")
> for i in "${names[@]}"

Yes, but not with /bin/sh. OK, it's usually possible to just change the
interpreter to /bin/bash, but with /bin/sh the $@ array can be used:

    $ set -- "first item" "second item"
    $ for i in "$@"; do echo "$i"; done
    first item
    second item


Reply to: