Find the answer to your Linux question:
Results 1 to 4 of 4
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...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2006
    Posts
    4

    [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

  2. #2
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    You might want to try the eval shell command instead of the backticks; maybe that'll work.
    Flies of a particular kind, i.e. time-flies, are fond of an arrow.

    Registered Linux User #408794

  3. #3
    Just Joined!
    Join Date
    Jun 2006
    Posts
    4

    Thumbs up

    Quote Originally Posted by Javasnob
    You might want to try the eval shell command instead of the backticks; maybe that'll work.
    Thanks, works like a charm.

  4. #4
    Just Joined!
    Join Date
    Oct 2009
    Posts
    1
    used it without the backtick and it worked!

    regards,
    borncrusader

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •