The UNIX and Linux Forums  

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
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 07:06 PM
awk and execute command ??? sabercats Shell Programming and Scripting 13 03-28-2006 07:12 PM
Plz Help : How to use write command to execute command on some other terminal Aashish UNIX for Dummies Questions & Answers 2 03-03-2006 12:25 PM
How does this command execute? saneeshjose UNIX for Dummies Questions & Answers 3 01-03-2006 10:46 AM
execute command neer45 Shell Programming and Scripting 2 11-25-2001 08:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-29-2008
littlejon littlejon is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 4
How to build a command into a string rather than execute the command

I'm trying to populate a command line into a variable. It appears to be executing, instead. Here's an example:

mycmd=''
if ...; then
$mycmd='sudo '
fi
$mycmd=$mycmd 'sed -i prev s/aaa/bbb/' $myfile
res=`$mycmd`

(I'm also not sure of the best way to execute the command from the variable, either, so any corrections would be appreciated!)

Last edited by littlejon; 05-29-2008 at 08:56 PM..
  #2 (permalink)  
Old 05-29-2008
fabtagon fabtagon is offline
Registered User
  
 

Join Date: Apr 2008
Location: European Union/Germany
Posts: 189
Quote:
Originally Posted by littlejon View Post
$mycmd=$mycmd 'sed -i prev s/aaa/bbb/'
mycmd=$mycmd 'sed -i prev s/aaa/bbb/'

(no $ at the beginning of the line)

Quote:
execute the command from the variable

Code:
fab@adeon:~$ a="echo hi"
fab@adeon:~$ $a
hi
fab@adeon:~$ eval $a
hi


Last edited by fabtagon; 05-29-2008 at 09:08 PM.. Reason: 2nd question & markup fix
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 07:57 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