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

WhiteSilent

New Member
Joined
Jul 1, 2019
Messages
4
Reaction score
2
Credits
0
" ` " 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?
 


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.
 
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...)
 
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
 
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
 
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...
 


Top