Code Comments
Programming Forum and web based access to our favorite programming groups.say I have two programs in one directory
prg1
prg2
both program has some questions to ask, such as what's the directory,
yes or no and etc, and all different.
I tried
ls -l | awk '{print $11 }' | sh
I hope prg1 and prg2 will run consequentially, but actually no, prg2's
name has been treated as user's answer for "yes/no" and "directory".
Any suggestion to force prg1 get parameter from keyboard instead of
pipe?
Thanks a lot
Post Follow-up to this messageIn article <343e3ab2.0409161018.6ae041f3@posting.google.com>,
BlueDolphin <aliceliu106@yahoo.com> wrote:
% say I have two programs in one directory
%
% prg1
% prg2
[...]
%
% I tried
% ls -l | awk '{print $11 }' | sh
Think about why you're using ls here. Then think about why you're
using the -l switch to ls when all you want is the file name. Why
not use
ls | awk '{ print $1 }' | sh
? Of course, that simplifies to
ls | sh
albeit going off-topic in the process, and without solving your
problem.
One way to get the effect you crave is to run ls from within
awk, read its output using getline, and use the system command
to execute the commands:
awk 'BEGIN {
while ("ls" | getline)
system($0)
close("ls")
}'
If you really need the programs to run in the same shell, you can build
a command-line first
awk 'BEGIN {
cmd = ""
while ("ls" | getline)
cmd = cmd $0 ";"
close("ls")
system(cmd)
}'
Normally, I wouldn't use awk for this, though:
for a in prg*
do
$a
done
--
Patrick TJ McPhee
East York Canada
ptjm@interlog.com
Post Follow-up to this messageOn 17 Sep 2004 00:22:38 GMT in comp.lang.awk, ptjm@interlog.com
(Patrick TJ McPhee) wrote:
>Normally, I wouldn't use awk for this, though:
>
>for a in prg*
>do
if [ -x $a ]
then
> $a
fi
>done
--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
Brian.Inglis@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]a
b[dot]ca)
fake address use address above to reply
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.