LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-24-2008, 09:38 PM   #1
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Rep: Reputation: 15
what the difference between "\z" and "\\z"?


why i get the same result \z from "\z" and "\\z" ? thanks in advance!
 
Old 10-24-2008, 09:42 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
What is the context of this?----i.e. where are you entering these characters?
 
Old 10-24-2008, 10:09 PM   #3
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pixellany View Post
What is the context of this?----i.e. where are you entering these characters?
on the command line using shell. i am new to shell and learning it! thanks!!
 
Old 10-24-2008, 10:30 PM   #4
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pixellany View Post
What is the context of this?----i.e. where are you entering these characters?
why i get the result \,\z and not \,\\z when i type echo '\,'\\z'' on the command line? thanks very much!

Last edited by topheraholic; 10-24-2008 at 10:32 PM.
 
Old 10-24-2008, 10:31 PM   #5
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
Your question still makes no sense. Please post your complete command line in which this occurs.
 
Old 10-24-2008, 11:57 PM   #6
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by AuroraCA View Post
Your question still makes no sense. Please post your complete command line in which this occurs.
ok, i mean, why i get the \,\z result not the \,\\z when i type echo '\,'\\z'' on the command line?

j@sfz-laptop:~$ echo '\,'\\z''
\,\z


and i get the output \\,\\topher when i type echo '\\,\\topher' and get the another one \\,\topher when i type echo '\\,'\\topher''

j@sfz-laptop:~$ echo '\\,\\topher'
\\,\\topher
j@sfz-laptop:~$ echo '\\,'\\topher''
\\,\topher


is this clear? thanks!!

Last edited by topheraholic; 10-25-2008 at 12:15 AM.
 
Old 10-25-2008, 12:09 AM   #7
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
Thank you for the clarification.

Double and single quotes have different meaning in the Linux shells.

The \ character is a special character known as an escape character in Linux shells. Generally with the exception of the newline (/n) an unquoted \ uses the literal value of the character which follows it. A good example of this is if you wish to go to a directory or refer to a file which has spaces in it which is generally allowed in Windows but can be confusing in Linux.

To go to the directory "My Files" you would enter:
Code:
cd My\ Files
There are specific escape commands which when enclosed with quotes have special meaning in the shell.

Please refer to:

http://www.ss64.com/bash/syntax-quoting.html

for a more complete explanation.

In your example the first \ escapes the second \ with double quotes. If you wish to see \\z then you would need to enter using single quotes:

Code:
echo '\\z'
\\z
or
Code:
echo "\\\z"
\\z

Last edited by AuroraCA; 10-25-2008 at 12:27 AM.
 
Old 10-25-2008, 12:19 AM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
The backslash is used to escape characters that the shell would interpret non-literally. For example: ls this\ is\ a\ filename
If you don't escape the spaces, the shell will try: ls "this" "is" "a" "filename"
instead of: ls "this is a filename"
You may also use it to escape the new line character to continue arguments on another line:
Code:
ffmpeg -i videofile.avi \
       -b 7000k \
       -y videofile.mpg
This will also improve the readability.
Look at your example without the double quotes:
Code:
jschiwal@qosmio:~> echo \ \\z
 \z
The space is taken literally. A backslash has a special meaning, so to echo a backslash, you need to escape it with a backslash. Hence the two backslashes.

When you enclosed the expression in double quotes, a single backslash is taken literally if not preceded by a metacharacter, which the backslash is. So the first backslash caused the second one to be taken literally.

One more example may make this clear:
Code:
jschiwal@qosmio:~> echo "$DISPLAY"
:0
jschiwal@qosmio:~> echo "\$DISPLAY"
$DISPLAY
Variables are expanded inside double quotes. The backslash causes the dollar sign to be taken literally preventing expansion.

Last edited by jschiwal; 10-25-2008 at 12:22 AM.
 
Old 10-25-2008, 01:12 AM   #9
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
The backslash is used to escape characters that the shell would interpret non-literally. For example: ls this\ is\ a\ filename
If you don't escape the spaces, the shell will try: ls "this" "is" "a" "filename"
instead of: ls "this is a filename"
You may also use it to escape the new line character to continue arguments on another line:
Code:
ffmpeg -i videofile.avi \
       -b 7000k \
       -y videofile.mpg
This will also improve the readability.
Look at your example without the double quotes:
Code:
jschiwal@qosmio:~> echo \ \\z
 \z
The space is taken literally. A backslash has a special meaning, so to echo a backslash, you need to escape it with a backslash. Hence the two backslashes.

When you enclosed the expression in double quotes, a single backslash is taken literally if not preceded by a metacharacter, which the backslash is. So the first backslash caused the second one to be taken literally.

One more example may make this clear:
Code:
jschiwal@qosmio:~> echo "$DISPLAY"
:0
jschiwal@qosmio:~> echo "\$DISPLAY"
$DISPLAY
Variables are expanded inside double quotes. The backslash causes the dollar sign to be taken literally preventing expansion.


thanks! i just donot know the difference between single quoting and double quoting!!!
 
Old 10-25-2008, 01:34 AM   #10
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by topheraholic View Post
thanks! i just donot know the difference between single quoting and double quoting!!!
Well, the other posts here gave quite a few hints......

With single quotes, everything inside is protected from the shell---ie it is passed on the whatever process is being called.

With double quotes, certain things are allowed to be operated on by the shell. The most common example is "$".

To read up on the details, go to http://tldp.org and get the Bash Guide for Beginners, or the ultimate boat anchor: The Advanced Bash Scripting Guide (ABS).
 
Old 10-25-2008, 01:34 AM   #11
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep: Reputation: 15
how to use single quoting in single quoting?

'\\,'\\z''gets \\,\z ? why not \\,\\z

thanks!!!!!!!!!
 
Old 10-25-2008, 01:38 AM   #12
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
Hints? The link that I provided specifically and in detail explained the syntax of using quotes in the Linux shell. I don't know how to be more helpful than that. If people don't read the answers then there is not much purpose to this forum.
 
Old 10-25-2008, 01:39 AM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
It's not a good idea to start new threads when you are simply continuing the same basic topic. Please go to my last post in the other thread.

I'll suggest that this be merged.
 
Old 10-25-2008, 01:43 AM   #14
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
If you are not going to read the answers to your questions then you should really learn to use Google.

I answered your question in your other post and the details can all be found in the link that I provided in my answer to that post.

Quote:
There are specific escape commands which when enclosed with quotes have special meaning in the shell.

Please refer to:

http://www.ss64.com/bash/syntax-quoting.html

for a more complete explanation.
 
Old 10-25-2008, 01:44 AM   #15
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by AuroraCA View Post
Hints? The link that I provided specifically and in detail explained the syntax of using quotes in the Linux shell. I don't know how to be more helpful than that. If people don't read the answers then there is not much purpose to this forum.
I'd say that qualifies as a really good hint!.....
In fairness, I have been where OP is----when first encountered, some of the syntax of the shell can be a bit overwhelming.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie question: whats the difference between "su root", "su" and "su -&quo mojarron Slackware 9 12-07-2009 05:08 PM
What is the difference between "make deinstall clean" and "pkg_delete"? Mr_Shameless *BSD 3 04-20-2007 08:41 PM
Can you explain the difference between "Free Software (GNU)" and "Open Source"? vharishankar General 5 03-03-2005 10:40 AM
difference between "Web server local URL" and "IPv4 address"? kpachopoulos Linux - General 2 09-17-2004 02:30 PM
"User" & "System" CPU load difference JJX Linux - General 3 06-06-2004 02:42 AM


All times are GMT -5. The time now is 03:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration