Hi,
I want to store ^M character in a variable to be later written to a file. Can you please help.
TempOut="$_var1 `print '\x0D'` $_var1"
.....
....
echo $TempOut >> logfile
TempOut="$_var1 `echo -e '\x0D'` $_var1"
.....
....
echo $TempOut >> logfile
But both ways I am getting x0D in the output file.
Thanks & Regards
Have you tried replacing '\x0D' with '\r'?
Are you sure you want a <carriage-return> there instead of a <newline>?
The easy, portable way to get what you asked for is:
TempOut=$(printf '%s \r %s' "$_var1" "$_var1")
.....
....
printf '%s\n' "$TempOut" >> logfile
If you're using an old Bourne shell that doesn't accept $(command)
replace the 1st line with:
TempOut=`printf '%s \r %s' "$_var1" "$_var1"`