zzh@ZZHPC:~$ a=" aaa aaa " zzh@ZZHPC:~$ echo "$a" aaa aaa zzh@ZZHPC:~$ echo $a aaa aaa zzh@ZZHPC:~$ b="bbb${a}bbb" zzh@ZZHPC:~$ echo "$b" bbb aaa aaa bbb zzh@ZZHPC:~$ echo $b bbb aaa aaa bbb zzh@ZZHPC:~$ c="ccc ${a} ccc" zzh@ZZHPC:~$ echo "$c" ccc aaa aaa ccc zzh@ZZHPC:~$ echo $c ccc aaa aaa ccc zzh@ZZHPC:~$ d="ddd ${a} ddd" zzh@ZZHPC:~$ echo "$d" ddd aaa aaa ddd zzh@ZZHPC:~$ echo $d ddd aaa aaa ddd
Shell will trim leading and trailing space or tab characters and also squeeze sequences of tabs and spaces into a single space when assigning a string to a variable.
zzh@ZZHPC:~$ echo " aaa " > aaa.txt zzh@ZZHPC:~$ cat aaa.txt aaa zzh@ZZHPC:~$ cat aaa.sh while read line do echo $line echo "$line" echo "bbb${line}bbb" done < aaa.txt zzh@ZZHPC:~$ ./aaa.sh aaa aaa bbbaaabbb