The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Splitting the data and storing it into 2 variables jisha Shell Programming and Scripting 10 02-17-2008 10:40 PM
Using variables in sed commands hcclnoodles Shell Programming and Scripting 2 01-02-2007 08:56 AM
Referencing variables in commands mharley Shell Programming and Scripting 3 03-31-2005 01:37 AM
awk - storing data in variables 2nilotpal Shell Programming and Scripting 7 04-16-2004 05:32 AM
Subing Variables with commands. Astudent UNIX for Dummies Questions & Answers 1 02-26-2001 05:02 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-13-2007
Paulw0t Paulw0t is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 10
Storing commands in $variables.

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.
  #2 (permalink)  
Old 03-13-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
you need to try it something like this,

Code:
value=`echo abcd | sed 's/..//g'`
echo $value
  #3 (permalink)  
Old 03-13-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Try:

Code:
eval $t1
Regards
  #4 (permalink)  
Old 03-13-2007
Paulw0t Paulw0t is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 10
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.

Last edited by Paulw0t; 03-13-2007 at 11:52 AM..
  #5 (permalink)  
Old 03-13-2007
Paulw0t Paulw0t is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 10
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
  #6 (permalink)  
Old 03-13-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Try to quote the variable like this:

Code:
eval "$t1"
or for your last command:

Code:
eval "$lastcmd"
Regards
  #7 (permalink)  
Old 08-08-2008
AnbeSivam AnbeSivam is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 1
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0