Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to write a script that will dump all partitions of my android device through the android debug bridge and since this is a time intensive process I want to notify the user about the progress by echoing out messages after certain key events happen. To my surprise I have noticed that sometimes echo does not print all the characters that it should.

The smallest sample that reproduces the error is:


targets=$(adb shell "ls /dev/block/nand*")

for item in $targets; do
    echo "Processing $item"
    echo "dd if=$item bs=4M"

This produces the following output:

Processing /dev/block/nanda
dd if=/dev/block/nanda bs=4M
Processing /dev/block/nandd
dd if=/dev/block/nandd bs=4M
Processing /dev/block/nandg
dd if=/dev/block/nandg bs=4M
Processing /dev/block/nandj
Processing /dev/block/nandb
dd if=/dev/block/nandb bs=4M
Processing /dev/block/nande
dd if=/dev/block/nande bs=4M
Processing /dev/block/nandh
Processing /dev/block/nandc
dd if=/dev/block/nandc bs=4M
Processing /dev/block/nandf
dd if=/dev/block/nandf bs=4M
Processing /dev/block/nandi

Why does this happen and how can I fix it?

share|improve this question
up vote 6 down vote accepted

Your $item ends with a carriage return, so the cursor zips back to the beginning of the line and prints <space>bs=4M

You can do item=${item%$'\r'}

share|improve this answer
That was it. Thank you! – Mihai Bişog Jun 26 '13 at 20:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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