PDA

View Full Version : [SOLVED] bash add space



MikeCyber
August 17th, 2017, 10:59 AM
Hi
I simply want to add space in a line with bash. For ex:
echo $id $idd xp$c >> ./mass.txt
should give something alike:

id idd xp
and not:
id idd xp
Thanks

TheFu
August 17th, 2017, 01:18 PM
The forum has "code tags" - Adv Reply (# button) - or in the Advanced Editor - or am I missing the question completely?

echo $id $idd xp$c >> ./mass.txt

So I was completely missing the point.
You can just quote everything.

echo "$id $idd xp$c " >> ./mass.txt

spjackson
August 17th, 2017, 03:46 PM
echo "$id $idd xp$c " >> ./mass.txt

or something like...


printf "%-10s, %7s %8s \\n" "$id" "$idd" "xp$c" >> ./mass.txt

depending on how many spaces you want where and whether you want data left or right justified within a field. See 'info printf' for details.

MikeCyber
August 18th, 2017, 06:22 AM
Thanks. I'll try in the next days.