Hi I'm trying to store commands in variables... like so..
# lastcmd=" $t1 | $t2 | $t3 | $t4 | sort | uniq"
t1="sed -e 's/http:/<li><a href=\"http:/'"
t2="sed -e 's/http:./&\">&<\/a>Web Link<br>/'"
t3="sed -e 's/.[0-9]. mailto:/<li><a href=\"mailto:/'"
t4="sed -e 's/mailto:.*/&\">&<\/a>Email Link<br>/'"
The code will work when not in the variables but its messy is there any way of storing these things like above ?
echo $t1
etc
Produces the desired string I'm wanting to run... Any suggestions ?
sed: -e expression #1, char 1: unknown command: `''
is the error I get when I try to run the script....
The code that i'm running to test this part is
t1="sed -e 's/http:/<li><a href=\"http:/'"
t2="sed -e 's/http:./&\">&<\/a>Web Link<br>/'"
t3="sed -e 's/.[0-9]. mailto:/<li><a href=\"mailto:/'"
t4="sed -e 's/mailto:.*/&\">&<\/a>Email Link<br>/'"
lynx -dump "$1" | \
sed -e '1,/^References$/d' \
-e 's/.*[0-9]. //' | \
$t1|$t2|$t3|$t4
Thanks. Paul.
you need to try it something like this,
value=`echo abcd | sed 's/..//g'`
echo $value
Thanks the eval worked... but it doesn't full work with the varible... tried with echo didn't seem to work. Just outputed it to the screen.
t1="sed -e 's/http:/<li><a href=\"http:/'"
t2="sed -e 's/http:./&\">&<\/a>Web Link<br>/'"
t3="sed -e 's/.[0-9]. mailto:/<li><a href=\"mailto:/'"
t4="sed -e 's/mailto:.*/&\">&<\/a>Email Link<br>/'"
#lastcmd="eval $t1| eval $t2| eval $t3| eval $t4 | sort |uniq"
lynx -dump "$1" | \
sed -e '1,/^References$/d' \
-e 's/.*[0-9]. //' | \
eval $t1| eval $t2| eval $t3| eval $t4 | sort |uniq
That will work however I would like to replace the
"eval $t1| eval $t2| eval $t3| eval $t4 | sort |uniq" with $last command..
THe #ed line above will not work when called like this...
lynx -dump "$1" | \
sed -e '1,/^References$/d' \
-e 's/.*[0-9]. //' | \
eval $lastcmd
or using $lastcmd with out the eval....
Any suggestions of how to put those all inside lastcmd ?
Thanks.
lastcmd="sed -e 's/http:/<li><a href=\"http:/'| sed -e 's/http:./&\">&<\/a>Web Link<br>/'| sed -e 's/.[0-9]. mailto:/<li><a href=\"mailto:/'| sed -e 's/mailto:.*/&\">&<\/a>Email Link<br>/' | sort | uniq"
This will do the job without using the t1/2 variables only i can't put it on new lines etc and makes for hard to read code :S
Try to quote the variable like this:
eval "$t1"
or for your last command:
eval "$lastcmd"
Regards
Thank you that worked great..
eval "$lastcmd"
I am facing a similar problem in Perl.
my $command = "$scp $repository/$nameoffile user@$server:/dir/$name";
This line is not executing and I don't know how to capture this error from the shell in perl.
Can anyone help me with this? It would be much appreciated.