Unable to echo the content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to echo the content
# 15  
Old 02-22-2013
ksh has a funny behavior with e.g.
Code:
echo "\\a"

I did not find an explanation in man ksh,
but it helped to replace echo with printf...:
Code:
printf "%s\n" "\\a"

# 16  
Old 02-22-2013
In echo \a is a meta character, even if echo is a bash built in (mimics the exec()-able command /bin/echo): Man Page for echo (opensolaris Section 1) - The UNIX and Linux Forums

echo '\01' is cntrl-a cntrl-j is 0x010A.
# 17  
Old 02-22-2013
I found it now in man echo on Solaris.
It describes /usr/bin/echo that is widely identical with the echo in ksh.

So the problem is the first character of `hostname` following a \ is treated specially.
The solution really is
Code:
printf "%s\n" "XYZ\\`uname -n`-volume" >> 123


Last edited by MadeInGermany; 02-22-2013 at 02:40 PM..
This User Gave Thanks to MadeInGermany For This Post:
# 18  
Old 02-22-2013
But if you are escaping one, you need to escape both.
# 19  
Old 02-22-2013
Quote:
Originally Posted by MadeInGermany
ksh has a funny behavior with e.g.
Code:
echo "\\a"

I did not find an explanation in man ksh,
but it helped to replace echo with printf...:
Code:
printf "%s\n" "\\a"

We've gone over this several times before in other threads. The echo command is not portable if the 1st argument starts with a minus sign or if any argument contains a backslash character.

This isn't ksh versus bash or other shells; it is whether the echo on your system behaves as specified by UNIX System V, as specified by BSD, or as specified by Linux. All three behave differently when parsing options and when handling backslash characters.

If you are trying to write a portable script use printf instead of echo whenever it is possible that the arguments you would be passing to echo violate either of these constraints.
This User Gave Thanks to Don Cragun For This Post:
# 20  
Old 02-22-2013
You could just type in echo 'cntrl-v cntrl-a', a quoted real SOH character.
# 21  
Old 02-22-2013
Code:
printf "%s\n" "XYZ\\`uname -n`-volume" >> 123

Worked, thanks alot guys.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to print "|" in echo

I have a small script that works well but when I am putting pipes at the end of the echo command, output is getting weird. My script it below: sed '1d' CONTROL_TOTALS_*.txt | while read eachline do tblnm=`echo $eachline | cut -d'_' -f3` if then stg_tblnm='PROVIDER_CONTRACT' elif then... (6 Replies)
Discussion started by: svks1985
6 Replies

2. Shell Programming and Scripting

Facing issues with Content-Type:application/x-download Content-Disposition:attachment

I am in the process of developing a perl cgi page. I had succeeded in developing the page but there are few errors/issues with the page. description about cgi page: My CGI page retrieves all the file names from an directory and displays the files in drop down menu for downloading the... (5 Replies)
Discussion started by: scriptscript
5 Replies

3. Shell Programming and Scripting

Unable to echo single quotes inside awk

# echo 'export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk '{print \$1}')' >> new_file # # cat new_file export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk {print $1}) # Now how to echo the quotes around the... (2 Replies)
Discussion started by: proactiveaditya
2 Replies

4. Shell Programming and Scripting

Help with remove duplicate content and only keep the first content detail

Input data_10 SSA data_2 TYUE data_3 PEOCV data_6 SSAT data_21 SSA data_19 TYUEC data_14 TYUE data_15 SSA data_32 PEOCV . . Desired Output data_10 SSA data_2 TYUE data_3 PEOCV data_6 SSAT data_19 TYUEC (9 Replies)
Discussion started by: patrick87
9 Replies

5. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

6. AIX

Unable to get the full content into a file when I redirect installp command output..

When i use the command to check the preview of the filesets to be installed using CLI # When using this commad 'm able to see all Preview view of the filesets to be installed installp -apgX -d "." all # When I redirected the same output to a file 'm able to see only half the details... (1 Reply)
Discussion started by: Sounddappan
1 Replies

7. Shell Programming and Scripting

sed, awk [TAG]$content[/TAG] How to get var in $content in textfile?

Hello, I got a Qstion. Im posting to a phpbb forum with bash and curl.. i have a text file with the following tags that i post to the forum: $var1 $var2 $var3 How can i with sed or awk put var content from shell script between the ... in the... (7 Replies)
Discussion started by: atmosroll
7 Replies

8. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

9. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies
Login or Register to Ask a Question