Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing an octal string as ASCII characters using echo command

I am trying to create a shell script from java code. I am using following method to create the shell script.

 String cmd = "echo -e \"echo -e abc\\\0177\\\0177\\\0177\\\0177\\\0177\\\0177\\\0177\\\0177\" > ";

    String [] commands = { "/system/bin/sh", "-c", cmd + "script.sh " }; 
    Runtime.getRuntime().exec(commands);

However, when I open the script.sh file I see following :

echo -e abc\*7\*7\*7\*7\*7\*7\*7\*7

What I want is the following:

echo -e "abc\0177\0177\0177\0177\0177\0177\0177\0177"

What is wrong with I am doing ? Any idea how to fix this ?

like image 541
aMa Avatar asked Dec 14 '25 13:12

aMa


1 Answers

Not sure why you need this but you can use single quote in echo and 2 backslashes:

String cmd = 
 "echo -e 'echo -e abc\\\\0177\\\\0177\\\\0177\\\\0177\\\\0177\\\\0177\\\\0177\\\\0177' > ";
like image 200
anubhava Avatar answered Dec 17 '25 09:12

anubhava



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!