I am trying to execute a command in a string that contains hexadecimal escape sequences such as \x20.
For example, if the string is ls\x20/usr/bin/, then I want to run the command ls /usr/bin/.
How can I do this?
Well the readable way contains 3 lines:
CMD="ls\x20/usr/bin/"
OUTPUT="$(echo -e $CMD)"
eval "${OUTPUT}"
the echo -e will convert the string and the converted string will be stored in OUTPUT.
then just use eval :)
Hope it will help you
In one line (just as you said):
$(echo -e "ls\x20/usr/bin/")
Note: this way is one line but it doesn't work with everything.. It won't work with aliases for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With