The UNIX and Linux Forums  


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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #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..