1

Lets say that I have a file (executable) called literally 'a\b'. It just echoes some stuff. Now I want to call that and I can do it by inputting

user@machine:~/test$ ./a\\b

into my console. Now lets write this into a variable

user@machine:~/test$ COMMAND="./a\\b"

and now I want to execute this file 'a\b' by using backticks. Here is the result:

user@machine:~/test$ `$COMMAND`
a: command not found
user@machine:~/test$

So, here is my question: How can I make this work?

Ive tried numerous ways and played around with '' and multiple backslashes in COMMAND but nothing worked...

I know its senseless but I just want to know how bash and `` work together to interpret things

4

I think your executable file just prints a to the screen. When you write $COMMAND, file executed and the output tried to be executed again.Because it cannot execute a command, it gives an error. You can use just simply $COMMAND or echo `$COMMAND`

  • 1
    He doesn't need the `` those are executing the result of the script as if that was another command – YoMismo Jan 30 '15 at 12:08
  • 1
    Change the output of the a\b command to hello or something similar to distinguish the "a" of the command name from the "a" of the output. – wurtel Jan 30 '15 at 12:08
  • 1
    Ah I see, the real problem consists of the fact that I do not understand the backticks... – Fabian Werner Jan 30 '15 at 12:51
  • 2
    @FabianWerner: Instead of echo "hello" in your a\b script try echo "date". And in general, don't use backticks in bash, use $(some_command), it's more versatile (eg it can be nested, if required), and it's easier to read. Also, it's easier to write in Stack Exchange comments. :) – PM 2Ring Jan 30 '15 at 13:16
  • I think I was misunderstanding whart the backticks (or $(...) if you want) do... It is like 1) remove the stringn with backticks 2) evaluate the string in between the backticks 3) open a new shell 4) type into the new shell word by word the result from the evaluation of the string in between the backticks 5) put the stdout of this second shell where the backticks with string inside was in the first original shell and close the second shell... – Fabian Werner Jan 30 '15 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.