Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ignoring delimiters when passing to variable 1

Status
Not open for further replies.

chris01010

Programmer
Jan 29, 2004
25
GB
Morning,

i'm currently having trouble when passing a value into a variable from another file. I am currently using the below example:
Code:
function Command
{
for command in `cat proclst.tmp`
do

set $command

exec $command

done

}
The line I am trying to pass has a space delimiter (and is actually a command to be executed), unfortunately the variable only gets set with the first part of the line.

e.g.

the line acutally reads

/usr/local/function stop

but the variable is passed only

/usr/local/function


Any ideas how to get round this?

Cheers

Chris
 
function Command
{
awk '{ system("set " $0); system("exec " $0) }' proclst.tmp
}
 
If the commands are by line then you can do

Code:
while read line < proclst.tmp
do
 your stuff
done
 
The [tt]exec[/tt] command will never return. I'm not sure this is what you want ( since you put it in a loop ! ).

If you just want to execute all shell commands store in a file you could go reading line by line like ericbrunson's suggested:
Code:
function Command {
  while read line; do
    eval $line
  done < proclst.tmp
}

But why do you not simply 'source' them:
Code:
function Command {
  . proclst.tmp
}

--------------------

Denis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top