I'm executing a shell script and one of the commands is creating a file with text via echo.
However, if the text within echo has "\t" or similar, it automatically translates it into a TAB character, same goes for other special characters.
I know that if I put another "\" before it would ignore it and proceed as desired.
ex:
\t => TAB (notok)
\\t => \t (ok)
But I don't intend to search for possible scenarios every time I run the script and was looking to create the file using print or similar (hoping that there is another way to remove this automatic translation of special chars. ) but I'm not so familiar with this function yet.
echo will give undetermined results across shells and/or platforms when using special characters. The best way to get predictable behavior is to use printf with a format specifier.
should reliably and constantly produce the output you require in any Posix or Bourne type shell across platforms.....
---
To get consistent echo behavior, you could add a simple function at the start of the script, that overrides the echo builtin and emulates the desired echo behavior (without the -n option)
This should work, provided IFS is set to the standard $' \t\n' (space-tab-newline).
--
But to create a text file I would use a here document instead of printf commands..
For example
Note that the second EOF has to be at the start of the line
Last edited by Scrutinizer; 04-16-2015 at 01:30 AM..
This User Gave Thanks to Scrutinizer For This Post:
echo will give undetermined results across shells and/or platforms when using special characters. The best way to get predictable behavior is to use printf with a format specifier.
should reliably and constantly produce the output you require in any Posix or Bourne type shell across platforms.....
---
To get consistent echo behavior, you could add a simple function at the start of the script, that overrides the echo builtin and emulates the desired echo behavior (without the -n option)
This should work, provided IFS is set to the standard $' \t\n' (space-tab-newline).
--
But to create a text file I would use a here document instead of printf commands..
For example
Note that the second EOF has to be at the start of the line
Your suggestion using a here document worked best for all purposes. I don't even have to worry about quotes and double quotes using this solution. The script is much more improved now.
Thank you very much.
EDITED: With this option, I just realized that I'm not able to input dollar sign as text, it will remove the entire variable. Do you have a workaround for this too without having to put \ before the $ sign?
Currently using below script but echo it print the output in two line.
Input file all-vm-final-2.txt
CEALA08893 SDDC_SCUN DS_SIO_Workload_SAPUI_UAT_01 4
CEALA09546 SDDC_SCUN DS-SIO-PD5_Workload_UAT_SP1_Flash_07 4
CEALA09702 SDDC_SCUN DS-VSAN-RMP-WORKLOAD01 4
DEALA08762 SDDC_LDC... (3 Replies)
I am using echo in bash. Have created a function prargv which takes a number of arguments.
Example:
prargv "-e" "--examples"
Inside prargv, I want to print all the arguments using echo
echo "$@"
This returns
--examples
rather than
-e --examples"
This problem can be fixed... (3 Replies)
Hi,
Iam using ksh and trying to execute the following syntax to replace one word of the sentence with a new word. But somehow sed is not able to replace the old value with new value. Please let me know where Iam going wrong.
Sample Code :
-->
export line="VORTEX,abcdef"
export... (3 Replies)
Hi,
I have written this code
------------------------------------------------
# !/bin/ksh
i=0
while
do
j=$i
while
do
echo -e $j
#printf "%d",$j
j=`expr $j - 1`
done
echo
i=`expr $i + 1`
done
----------------------------------------------------
The ouput which... (2 Replies)
Hi All,
I'm using KSH and am writing a small script that counts the lines of various files in several folders under one root folder.
Below is the script:
#!/usr/bin/ksh
common_path_in="/interface_in/rsc"
file_out="/interface_in/rsc/record_count.csv"
tot_rec_count=-1
act_rec_count=-1... (5 Replies)
how to print 3 backslah using Unix AIX,
i have try in my fedora and AIX,both give dirrent output for same echo statment
test.sh
sed -e 's/\(\)/\\\1/g' -e 's/\$?/\\$?/g' -e 's/\$#/\\$#/g' -e 's/^/echo "/g' -e 's/$/ "/g' xMNBDF070 > xMNBDF070_test
xMNBDF070
sed -e "s/'/\\\'/g" -e... (8 Replies)
I did a search for this topic but I couldn't find it and I was sure I have seen something similar before (hard because I am not sure of the criteria for the keywords)
What I was looking for was to be able to echo a message to the screen from a bash.sh script at the same time logging it to a... (2 Replies)