In Linux shell bash script, how to print to a file at the same line?
After wading through that question, I've decided that what you're looking for is
If you are looking for a single tab in between the variables, then printf is a good choice.
printf '%s\t%s' "$v1" "$v2" >> file_name
If you want it exactly like your example where the tab is padded with a space on both sides:
printf '%s \t %s' "$v1" "$v2" >> file_name
few options there:
echo -n foo barIt's simple, but may not work on some old UNIX systems like HP-UX or SunOS. Instead the "-n" will be printed as well as the rest of the arguments followed by new line.
echo -e "foo bar\c". The
\chas meaning: "produce no further output". I don't like this solution personally, but some UNIX wizards use it.
printf %b "foo bar"I like this solution the most. It's quite portable as well flexible.
echo -n to trim the newline. See if that works
Related videos on Youtube
user1002288 6 months
In Linux shell bash script, how to print to a file at the same line ?
At each iteration,
echo "$variable1" >> file_name, echo "$variable2" >> file_name,
but echo insert a newline so that it becomes
$v1 \tab $v2
"\c" cannot eat newline.
does not help .