1837228 Members
2815 Online
110115 Solutions
New Discussion

IFS and awk

 
SOLVED
Go to solution
Mario_88
Advisor

IFS and awk

Hello:

What I want is given the following sequence of commands:

commands="cmviewcl -v;ls -al; netstat -an"

execute them one by one. I tried the following

export COMMANDS="cmviewcl -v;netstat -an"
init()
{
export IFS=";"
for i in $@
do
$i
done
}
init $COMMANDS


But it doesnt work and tries to execute the commands: cmviewcl, -v, netstat, -an

Regards,
Mario.

3 REPLIES 3
Vibhor Kumar Agarwal
Esteemed Contributor
Solution

Re: IFS and awk

Try this:

export COMMANDS="cmviewcl -v;netstat -an"
init()
{
for i in $@
do
$i
done
}

export IFS=";"
init $COMMANDS
Vibhor Kumar Agarwal
Mario_88
Advisor

Re: IFS and awk

thanks.
Vibhor Kumar Agarwal
Esteemed Contributor

Re: IFS and awk

Did you get the reason.

The IFS should be there before passing the parameters, in your case the parameters were passed keeping the default IFS.
Vibhor Kumar Agarwal