Executing a command named in a variable

Nils Kassube kassube at gmx.net
Tue Dec 1 10:35:11 UTC 2009


Ray Parrish wrote:
> Would the following work?
> 
> # set variable to command line
> ExecuteEditor="/usr/bin/gedit filename.ext"
> # execute external command.
> $ExecuteEditor &

No, it wouldn't work because bash will look in /usr/bin for a command 
"gedit filename.ext" which doesn't exist. You would need the eval 
command here but you might as well write it this way:

ExecuteEditor=/usr/bin/gedit
File=filename.ext
$ExecuteEditor $File &


Nils




More information about the ubuntu-users mailing list