[NTLUG:Discuss] bash question: executing a list of commands
gan hawk
ganhawk1 at hotmail.com
Sun Feb 22 21:57:25 CST 2004
Hi,
while read i; do `echo $i`; done < foo
seems to work for me. foo contained list of commands
echo a
echo b
echo c
and it printed
a
b
c
Ganesh
>From: Lance Simmons <lance at lsimmons.net>
>Reply-To: NTLUG Discussion List <discuss at ntlug.org>
>To: discuss at ntlug.org
>Subject: [NTLUG:Discuss] bash question: executing a list of commands
>Date: Sun, 22 Feb 2004 21:45:56 -0600
>
>Suppose I have a file named foo with a series of commands I want
>execute. E.g.,
>
> ls -l
> ls -lt
> ls -ltr
>
>How do I execute the lines of foo in order? I've tried
>
> for i in `cat foo`; do "$i"; done
> for i in "`cat foo`"; do "$i"; done
>
>and several others, but haven't been able to make it work.
>
>I've tried using xargs, by editing foo to contain only the lines
>
> -l
> -lt
> -ltr
>
>and then doing
>
> xargs -p ls < foo
>
>but the resulting command line is
>
> ls -l -lt -ltr
>
>not the desired
>
> ls -l
> ls -lt
> ls -ltr
>
>What am I missing? How do I take an arbitrary list of commands and
>execute them seriatim?
>
>(As to why I don't just put the commands in a script and execute them
>directly, the answer is that I want to build the list of commands as
>output from another command. In other words, I want the equivalent of
>the find command's -exec option.)
>
>--
>Lance Simmons
>
>_______________________________________________
>https://ntlug.org/mailman/listinfo/discuss
_________________________________________________________________
Stay informed on Election 2004 and the race to Super Tuesday.
http://special.msn.com/msn/election2004.armx
More information about the Discuss
mailing list