2

I am getting familiar with sed on the android terminal emulation: the version I am using the sed included in the toybox which is installed on my unrooted Sony device. sed --version (or toybox sed --version) gives out the same result:

This is not GNU sed 9.00

Now, I read the specific manual from toybox sed, and tried some simple one liners (the idea is to include those in scripts which I could launch manually). Now the first thing I noticed is that if I try to include the script in simple brackets (es sed -e 's/foo/bar/' file) this is not interpreted correctly.

The command works using the double brackets, but I am having problems with the way scripts are interpreted (or maybe I am doing things wrong). Example. I try to substitute a word inside a file. The file is a string "stringa di test", which I intend to convert into "stringa di prova". The result is that the string is substituted, but the previous string is attached to rest of the line:

user:$ ls
 file.txt
 n.sh
 s.sh
 save
 script_gian.sh
 sed_script
user: $ cat file.txt
 stringa di test
user:$sed -i -e "s/test/prova/g" file.txt                        <
 ^C1|user:$ cat file.txt
stringa di test
user:$  sed -r -e "s/test/prova/1" file.txt > f.txt                <
user:$ ls
 f.txt
 file.txt
 file.txtFD4OVI
 n.sh
 s.sh
 save
 script_gian.sh
 sed_script
user:$ cat f.txt
stringa di provastringa di test
user:$ cat file.txt
 stringa di test
user: $

Another interesting thing is that trying to use the g flag (global) results in sed hanging up and having to be interrupted with CONTROL C. -i command also results in sed hanging up.

I also tried to pipe a string to sed with :

cat file.txt | sed -e "s/foo/bar/" > newfile.txt

But the result is exactly the same. The word inside the string is substituted, and the line as it was before the substitution is appended just after this (this also deletes the remaining characters in the line)- Am I using sed wrongly or there is something in the version of sed I am trying to use?

  • looks like a bug in toybox to me – cas May 18 '16 at 21:30
  • Yes, yesterday evening I tried out some commands from GNU sed and they work as intended using the same syntax. My only doubt is that there is a chance GNU sed and most of the guides / cheatsheets out there don't follow POSIX while toybox tries to be compliant. Anyway more likely a bug, as I did read the manual included. – Giankun May 19 '16 at 6:06
2

I could have it confirmed (thanks to the #toybox irc channel) that the issue was indeed a bug in toybox sed, which was supposed to have been solved, but Android M still ships with an outdated version of toybox. These are the links to the toybox mailing list (which alas, I had missed) where the issues had been discussed:

http://lists.landley.net/pipermail/toybox-landley.net/2016-January/007897.html

http://lists.landley.net/pipermail/toybox-landley.net/2015-September/004415.html

Too bad, I will have to wait for a current version of toybox with a future Android update.

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.