Bash: How to avoid a space at the beginning of a line?

Given this command in bash:

echo -e "a b "{1..3}" d e\n"
a b 1 d e
 a b 2 d e
 a b 3 d e

the output of line 2 ... begins with a space. Why is this? Where is it from? How can I avoid this?

I know how to get rid of it with sed or something else, but I would prefer to avoid it in the first place.

I just mentioned this along with the {..} syntax. Are there other similar cases without this?

update:

A useful solution is to remove the first letter with backspace:

echo -e "\ba b "{1..3}" d e\n"

or as Jared Ng suggests:

echo -e "\ra b "{1..3}" d e\n"

update 2:

We get rid of the leading lines of a new line:

echo -e "\na b "{1..4}" d e" | sed '1d'
echo -e "\na b "{1..4}" d e" | tail -n +2

or trailing:

echo -e "\ba b "{1..3}" d e\n" | sed '$d'
echo -e "\ba b "{1..3}" d e\n" | head -n 3
+5
source share
3 answers
echo -e "\ra b "{1..3}" d e\n"

Corrects this for me. Output:

a b 1 d e
a b 2 d e
a b 3 d e

(\r - - , )

bash ? echo "abc"{1..3}. , bash: abc1 abc2 abc3. ? {1..3} , . , echo "abc"{1..3}"\n", bash . , .

+6

{...} , ,

echo "a b "1" d e\n" "a b "2" d e\n" "a b "3" d e\n"

\n - , .

\n , ,

echo -e "\na b "{1..3}" d e"

(, )

 printf "%s\n" "a b "{1..3}" d e"
+4

, . , .

{1..3} , , arg (echo , ). printf ( @glenn).

[me@home]$ printf "%s\n" "a b "{1..3}" d e"
a b 1 d e
a b 2 d e
a b 3 d e
+1

All Articles