how to print backslah using echo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to print backslah using echo
# 8  
Old 04-12-2007
To explain the reason for:
echo '\\\\' output: \\
echo "\\\\" output: \

First we have to understand that when an unix command is called to be
executed, there is always two evaluations:
1) From the running shell.
2) From the unix command itself.

As an example:
rm abc*

The "rm" command only does a delete on a list of files, it does not do
anything else besides the actual delete, in other words, there is no
evaluation of file names.

When the command "rm abc*" is typed, the following happens:
1) The shell first translate "abc*", searching for all local files that begin
with "abc" and sends the entire list of files to the "rm" command.
2) The "rm" command sees a list of files to be deteled and does its job.

rm abc*
is the same as
rm "abc*"
and both are different from:
rm 'abc*'

If a local directory has the following files:
abc
abcdef
123abc
abc123
xyzabc

When rm abc* or rm "abc*" is entered, the shell searches the current
directory for files beginning with "abc" and send the following list of files
to the "rm" command to be deleted:
abc
abcdef
abc123

When rm 'abc*' is entered, the shell searches does not do any translation
of what is inside of the single quote and sends the following to "rm":
abc*

Since there is no file in the directory named "abc*", nothing is deleted!

The same applies for the "echo" command and the quotes.

Single quote ('): Everything inside is taking literally. In other words, the shell
sends the string the way it is without any translation to the unix command,
ie "echo", "sed", "rm", etc.

Double quote ("): Shell does a translation for what is inside.

Thus:
echo "\" --> Shell escape the second ", opens an input and waits for the
___________string to be closed with another ".
___________"echo" sees one double quote and whatever is typed.
echo '\' --> Shell keeps what is inside and
___________"echo" sees only one \.
echo "\\" --> Shell converts what is inside into one \ because of escape \
___________"echo" sees only one \.
echo '\\' --> Shell keeps what is inside and
___________"echo" takes the first \ as escape for the next character and
___________considers only one \.

From these values, you can explain any combination.

Last edited by Shell_Life; 04-12-2007 at 11:20 AM..
# 9  
Old 04-12-2007
Quote:
Originally Posted by mani_um
how to print 3 backslah using Unix AIX,

If you need more than two consecutive backslashes in your code, you should refactor it so that you don't need that many.

Do yourself a favour and make it easier to read.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Echo print on same line while loop using variable

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)
Discussion started by: ranjancom2000
3 Replies

2. Shell Programming and Scripting

Replacing echo with print

Hi everyone, 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 "\"... (7 Replies)
Discussion started by: demmel
7 Replies

3. Shell Programming and Scripting

Using echo to print arguments inside a function

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)
Discussion started by: kristinu
3 Replies

4. Shell Programming and Scripting

Print (echo) variable in a single line

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)
Discussion started by: rac
2 Replies

5. Shell Programming and Scripting

Echo print in different lines within email sent by Cron job

Hi all, I think this could have a simple solution, just I canīt get it so far. I have the script below that includes several echo commands in order to show that every part of the script have been executed. A cron job executes this script and when is completed the output is sent by email. ... (4 Replies)
Discussion started by: cgkmal
4 Replies

6. Shell Programming and Scripting

echo/print variable question

while read filer ; do echo $filer $1 $2; ssh $filer vfiler status -r | awk '/running/{host=$1}/Path:/{path=$2;print host,path}'; done < filers.list this will print node1 vfiler0 / vfiler2 /vol/vfiler2_vol0 vfilert /vol/vfiler_vol vfilert /vol/virt_vol where node1 = $filer. however how... (1 Reply)
Discussion started by: riegersteve
1 Replies

7. Shell Programming and Scripting

Using echo to print double quotes along with variable substitution

Hi, I am generating html code using cshell, but i am having one problem while printing double quotes, I need to write following code in file. where $var contains list of web address <a href="$var">$var</a> So i am using echo "<a href="$var">$var</a>" > file.html But with this " in... (4 Replies)
Discussion started by: sarbjit
4 Replies

8. Shell Programming and Scripting

Differenc between print and echo

can anyone explain me what is the difference between echo and print in shell programming? (3 Replies)
Discussion started by: chandhar
3 Replies

9. UNIX for Dummies Questions & Answers

echo vs. print

Is there a functional difference between echo and print? (1 Reply)
Discussion started by: PhilW
1 Replies

10. UNIX for Dummies Questions & Answers

echo or print to screen and file

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)
Discussion started by: Shakey21
2 Replies
Login or Register to Ask a Question