LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-09-2008, 09:26 AM   #1
linuxtyh
LQ Newbie
 
Registered: Dec 2006
Location: Hangzhou,Zhejiang,China
Distribution: Ubuntu, ArchLinux, SunSolaris
Posts: 12

Rep: Reputation: 0
how to use single quote in bash shell like: echo ''\'''


echo ''\'''
why this out put '

why echo '\'' doesn't work
thank you very much
 
Old 12-09-2008, 09:58 AM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
It will not work because the backslash is considered an "escape" character. To print a backslash, escape it with another one:
Code:
echo "\\"
 
Old 12-09-2008, 10:58 AM   #3
nflenz
Member
 
Registered: Feb 2006
Distribution: CRUX 2.4
Posts: 96

Rep: Reputation: 18
Code:
"\'"
Backslashes are escape characters. You are basically telling the shell to interpret the ' as a literal character.

Code:
'\''
Escape characters are ignored in single quotes.
 
Old 12-09-2008, 08:11 PM   #4
linuxtyh
LQ Newbie
 
Registered: Dec 2006
Location: Hangzhou,Zhejiang,China
Distribution: Ubuntu, ArchLinux, SunSolaris
Posts: 12

Original Poster
Rep: Reputation: 0
no I mean there are five single quots in the first command
there are 3 single quots in the second one

why the second cant work

Quote:
Originally Posted by indienick View Post
It will not work because the backslash is considered an "escape" character. To print a backslash, escape it with another one:
Code:
echo "\\"
 
Old 12-10-2008, 05:43 AM   #5
arunmathew1984
Member
 
Registered: Nov 2008
Posts: 31

Rep: Reputation: 15
It is not 5 single quotes - it is two double quotes and 1 single quote.
Hope this clarifies your query.

Linux Archive

Last edited by arunmathew1984; 12-20-2008 at 11:17 AM.
 
Old 12-10-2008, 05:56 AM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Quote:
Originally Posted by linuxtyh View Post
no I mean there are five single quots in the first command there are 3 single quots in the second one

why the second cant work
In the first example the first two single quotes embed a null string, then you have an escaped single quote and finally the two last single quotes which embed another null string, that is (in colorized text)
Code:
echo ''\'''
In the second example you have a literal backslash embedded in single quotes and an opening single quote without the ending one to complete the pair:
Code:
echo '\''
if you press enter, the secondary prompt appears and the shell wait for input until it encounters another closing single quote.
 
Old 12-11-2008, 11:56 PM   #7
linuxtyh
LQ Newbie
 
Registered: Dec 2006
Location: Hangzhou,Zhejiang,China
Distribution: Ubuntu, ArchLinux, SunSolaris
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
In the first example the first two single quotes embed a null string, then you have an escaped single quote and finally the two last single quotes which embed another null string, that is (in colorized text)
Code:
echo ''\'''
In the second example you have a literal backslash embedded in single quotes and an opening single quote without the ending one to complete the pair:
Code:
echo '\''
if you press enter, the secondary prompt appears and the shell wait for input until it encounters another closing single quote.
thank you colucix, your answer is thorough and clear, and helps me much
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xargs: unmatched single quote akudewan Linux - Newbie 5 07-28-2014 12:16 PM
Bash shell file... echo on? carlos_vcan Linux - Newbie 3 06-12-2008 10:10 PM
Double and single quote, Question in expect evilchild Programming 4 08-22-2004 05:34 PM
xargs: unmatched single quote fillatre Linux - Software 2 06-05-2004 10:04 PM
In BASH shell, what is the difference in usage between single and double quotes? davidas Linux - Newbie 2 04-05-2004 03:00 AM


All times are GMT -5. The time now is 03:57 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration