LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-25-2006, 10:56 PM   #1
michael_hk
LQ Newbie
 
Registered: Jun 2006
Distribution: Red Hat 9.0
Posts: 4

Rep: Reputation: 0
[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
 
Old 06-25-2006, 11:30 PM   #2
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
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.
 
Old 06-26-2006, 03:34 AM   #3
michael_hk
LQ Newbie
 
Registered: Jun 2006
Distribution: Red Hat 9.0
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
escape string in bash script so it can be used in command line BuckRogers01 Linux - Software 15 08-12-2010 09:38 AM
use grep and execute a command if string is found plisken Linux - General 6 07-28-2005 11:06 AM
remote command execute telnet with 1 command MPowers Linux - Networking 2 06-30-2005 06:31 AM
Bash way to tell if String is in String tongar Programming 3 06-16-2005 06:59 AM
Bash command $? failed to execute. Linh Programming 7 05-14-2004 11:11 AM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration