Reputation: 381
I've got a small script which is returning a string/path. This path is an executable, how can I run the executable? Thank you.
Example:
my_command commands other commands
... returns /home/mydesktop/myexecutable
I'd need to execute /home/mydesktop/myexecutable
Upvotes: 1
Views: 108
Reputation: 70314
You could try this:
`your_command args etc`
The backticks get replaced by the output of the command and that is then evaluated. Since it is at the start of the input line, bash
tries to execute it.
This is a handy trick to know, since you can use it for all sorts of fun:
cp your_file .backup/`date "+%Y-%m-%d"`_your_file
will prepend the current date to a copy of your file for poor mans backup...
EDIT: In the comments, we learned, that you should actually be using the $()
syntax. So, that amounts to:
$(your_command args etc)
and
cp your_file .backup/$(date "+%Y-%m-%d")_your_file
since you can nest this...
Upvotes: 2
Reputation: 47089
If it returns an executable script/program use:
chmod +x /home/mydesktop/myexecutable
/home/mydesktop/myexecutable
If it returns an executable STRING use:
eval STRING
Upvotes: 0