LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   [Bash] execute string as command (https://www.linuxquestions.org/questions/linux-newbie-8/%5Bbash%5D-execute-string-as-command-458312/)

michael_hk 06-25-2006 10:56 PM

[Bash] execute string as command
 
Hi,

I am trying to execute a string as command.

Code:

txt="echo \"abc\""
`$txt`

result
Code:

./test.sh: line 2: "abc": command not found
What am I doing wrong?

Thanks.

Michael

alunduil 06-25-2006 11:30 PM

I don't totally understand what you are trying to do, but if you need to send a command into a string there are couple of tricks:

Code:

$(command)
or

Code:

foo=`code`
` == backtick (found under the tilde, ~, key)

Regards,

Alunduil

P.S. If this isn't correct, just post back with more specifics, and I'll try again.

michael_hk 06-26-2006 03:34 AM

Quote:

Originally Posted by alunduil
I don't totally understand what you are trying to do, but if you need to send a command into a string there are couple of tricks:

Code:

$(command)
or

Code:

foo=`code`
` == backtick (found under the tilde, ~, key)

Regards,

Alunduil

P.S. If this isn't correct, just post back with more specifics, and I'll try again.

Thanks for your info. I found what I need is eval.


All times are GMT -5. The time now is 04:51 PM.