What's the different between " ` " and " ' " ?

WhiteSilent

New Member
" ` " is the punctuation left of number 1 in main keyboard area.
" ' " is the punctuation left of Enter key in main keyboard area.
-----
When I type these into CentOS 7, return different results.
$ basename `pwd`
[current directory's basename]
And...
$ basename 'pwd'
pwd
-----
Why?
Is former just used in shell to refer to a shell command?
 


dos2unix

Member
It's difference between a literal (exactly what you type) and a variable. (Some characters that are mapped to a value). Also double quotes " work as well.

I am not familiar with the basename command, but you get get the results of pwd by simply typing
"pwd" or echo $PWD.
 

WhiteSilent

New Member
It's difference between a literal (exactly what you type) and a variable. (Some characters that are mapped to a value). Also double quotes " work as well.

I am not familiar with the basename command, but you get get the results of pwd by simply typing
"pwd" or echo $PWD.
Thanks.
I have tried:
echo $(pwd)
$() works the same as " ` " (called backtick which I just knew it 5 minutes ago...)
 

wizardfromoz

Super Moderator
Staff member
Gold Supporter
G'day @WhiteSilent and welcome to linux.org :)

I am just moving this Thread to Command Line, where it will attract a greater view by people interested in such matters, although @dos2unix obviously found it :p

Cheers

Chris Turner
wizardfromoz

BTW still lovin' that car avatar, d2u
 

AlienResidents

Gold Member
Gold Supporter
Also, depending on your shell (your example looks like a bourne-compatible shell) , the usage of single quotes, double quotes, and $() is different. Single quotes (not backticks) in Bash (maybe other shells) also allow you to print unicode too e.g. echo -e $'\xef\x85\xbc'.

Hopefully your terminal can show unicode characters, and if so, I think some good examples might be:
Code:
$ echo -e `echo hello`
hello
$ 
echo -e '`echo hello`'
`echo hello`
$ echo -e $'\xef\x85\xbc' # prints a unicode penguin

$ echo -e $"\xef\x85\xbc" # prints a unicode penguin

$ echo $"\xef\x85\xbc"    # prints \xef\x85\xbc
\xef\x85\xbc
$ csh
% echo $(ls -l)
Illegal variable name.
% echo $'\xef\x85\xbc'
Illegal variable name.
% echo `echo hello`
hello
% echo 'echo hello'
echo hello
% exit
% exit
 

WhiteSilent

New Member
Also, depending on your shell (your example looks like a bourne-compatible shell) , the usage of single quotes, double quotes, and $() is different. Single quotes (not backticks) in Bash (maybe other shells) also allow you to print unicode too e.g. echo -e $'\xef\x85\xbc'.

Hopefully your terminal can show unicode characters, and if so, I think some good examples might be:
Code:
$ echo -e `echo hello`
hello
$
echo -e '`echo hello`'
`echo hello`
$ echo -e $'\xef\x85\xbc' # prints a unicode penguin

$ echo -e $"\xef\x85\xbc" # prints a unicode penguin

$ echo $"\xef\x85\xbc"    # prints \xef\x85\xbc
\xef\x85\xbc
$ csh
% echo $(ls -l)
Illegal variable name.
% echo $'\xef\x85\xbc'
Illegal variable name.
% echo `echo hello`
hello
% echo 'echo hello'
echo hello
% exit
% exit
Oh, plenty of Usage!
Thank you.
I'm typing these examples one by one now...
 

Members online

No members online now.

Latest posts

Top