Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use hex escapes in bash eval string?

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?

like image 843
cie Avatar asked Oct 24 '25 15:10

cie


1 Answers

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.

like image 178
I-V Avatar answered Oct 26 '25 06:10

I-V



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!