can't figure out an one-liner

Warren Block wblock at wonkity.com
Wed Jan 12 14:50:07 PST 2005


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


More information about the freebsd-questions mailing list