Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Jan 2005 15:50:06 -0700 (MST)
From:      Warren Block <wblock@wonkity.com>
To:        Toomas Aas <toomas.aas@raad.tartu.ee>
Cc:        questions@freebsd.org
Subject:   Re: can't figure out an one-liner
Message-ID:  <20050112152242.M95286@wonkity.com>
In-Reply-To: <41E58A4E.9000105@raad.tartu.ee>
References:  <41E58A4E.9000105@raad.tartu.ee>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 12 Jan 2005, Toomas Aas wrote:

> # for luser in 'joe peter bill'  { tar cf - -C /home $luser | tar xf - }
>
> ... but I keep getting error messages that luser is undefined.
>
> What am I doing wrong?

In csh, it's "foreach", like this (tested):

foreach luser (joe peter bill)
   echo $luser
end

The csh man page says: "Both foreach and end must appear alone on 
separate lines."

But you should not use csh for scripting[1].  Instead, stick to standard 
sh (tested):

for luser in joe bill ted; do echo $luser; done

But that's ugly.  Unless there's a good reason to stick with shell 
scripts, consider using Perl or Python[2] from the start.

[1] Google for it.
[2] I'd lean towards Python currently.  Shame about the string
     interpolation, though.

-Warren Block * Rapid City, South Dakota USA



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