What's the difference between $(stuff) and `stuff`?Command substitution declaration syntax in bash - which of...
Detect the first rising edge of 3 input signals
Is there any evidence to support the claim that the United States was "suckered into WW1" by Zionists, made by Benjamin Freedman in his 1961 speech
Why is PerfectForwardSecrecy considered OK, when it has same defects as salt-less password hashing?
Are there variations of the regular runtimes of the Big-O-Notation?
Does the 500 feet falling cap apply per fall, or per turn?
Would encrypting a database protect against a compromised admin account?
Why do Thanos' punches not kill Captain America or at least cause some mortal injuries?
Has there been evidence of any other gods?
Which other programming languages apart from Python and predecessor are out there using indentation to define code blocks?
Pre-1993 comic in which Wolverine's claws were turned to rubber?
Can 'sudo apt-get remove [write]' destroy my Ubuntu?
What does this quote in Small Gods refer to?
Why are parallelograms defined as quadrilaterals? What term would encompass polygons with greater than two parallel pairs?
We are two immediate neighbors who forged our own powers to form concatenated relationship. Who are we?
Should I pay on student loans in deferment or continue to snowball other debts?
Is there an application which does HTTP PUT?
How to evaluate sum with one million summands?
How do I compare the result of "1d20+x, with advantage" to "1d20+y, without advantage", assuming x < y?
Renting a house to a graduate student in my department
Examples where existence is harder than evaluation
What can cause an unfrozen indoor copper drain pipe to crack?
Why can't I prove summation identities without guessing?
Why was wildfire not used during the Battle of Winterfell?
Exception propagation: When to catch exceptions?
What's the difference between $(stuff) and `stuff`?
Command substitution declaration syntax in bash - which of these two is better practice?What does $( … ) mean in the shell?Different behavior of $() and ``What's the difference of get command output using`command`and $(command) in Shell?What's the practical difference between `command` and $(command)?What's the difference between `` and $()?Nesting back-ticked commandsGet exit status of process that's piped to anotherWhat does ` (backquote/backtick) mean in commands?bulk rename (or correctly display) files with special charactersWhat is the difference between a builtin command and one that is not?Compare two data streams without both being stored as filesWhat's the practical difference between `command` and $(command)?What's the difference between $@ and $*What's the difference between “realpath” and “readlink -f”In find -perm, what's the difference between “+6000” and “/6000”?What's the difference between substitution and piping to bashWhat's the difference between 'passwd' and 'chpasswd'?Can it be explained; the difference in array behavior between the use of array=$( command ) and array=( $( command ) )?Does the syntax of not equal matter?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
There are two syntaxes for command substitution: with dollar-parentheses and with backticks.
Running top -p $(pidof init)
and top -p `pidof init`
gives the same output. Are these two ways of doing the same thing, or are there differences?
shell command-line command-substitution
add a comment |
There are two syntaxes for command substitution: with dollar-parentheses and with backticks.
Running top -p $(pidof init)
and top -p `pidof init`
gives the same output. Are these two ways of doing the same thing, or are there differences?
shell command-line command-substitution
18
See also: BashFAQ/082.
– Dennis Williamson
Jan 13 '11 at 16:38
40
For a second there I thought this was a jQuery question.
– David Murdoch
Jan 13 '11 at 20:42
The result might depend on the shell - some support both.
– artdanil
Feb 15 '11 at 22:33
add a comment |
There are two syntaxes for command substitution: with dollar-parentheses and with backticks.
Running top -p $(pidof init)
and top -p `pidof init`
gives the same output. Are these two ways of doing the same thing, or are there differences?
shell command-line command-substitution
There are two syntaxes for command substitution: with dollar-parentheses and with backticks.
Running top -p $(pidof init)
and top -p `pidof init`
gives the same output. Are these two ways of doing the same thing, or are there differences?
shell command-line command-substitution
shell command-line command-substitution
edited Jan 12 '14 at 2:21
Gilles
552k13211291637
552k13211291637
asked Jan 13 '11 at 11:02
TshepangTshepang
26.8k72188267
26.8k72188267
18
See also: BashFAQ/082.
– Dennis Williamson
Jan 13 '11 at 16:38
40
For a second there I thought this was a jQuery question.
– David Murdoch
Jan 13 '11 at 20:42
The result might depend on the shell - some support both.
– artdanil
Feb 15 '11 at 22:33
add a comment |
18
See also: BashFAQ/082.
– Dennis Williamson
Jan 13 '11 at 16:38
40
For a second there I thought this was a jQuery question.
– David Murdoch
Jan 13 '11 at 20:42
The result might depend on the shell - some support both.
– artdanil
Feb 15 '11 at 22:33
18
18
See also: BashFAQ/082.
– Dennis Williamson
Jan 13 '11 at 16:38
See also: BashFAQ/082.
– Dennis Williamson
Jan 13 '11 at 16:38
40
40
For a second there I thought this was a jQuery question.
– David Murdoch
Jan 13 '11 at 20:42
For a second there I thought this was a jQuery question.
– David Murdoch
Jan 13 '11 at 20:42
The result might depend on the shell - some support both.
– artdanil
Feb 15 '11 at 22:33
The result might depend on the shell - some support both.
– artdanil
Feb 15 '11 at 22:33
add a comment |
6 Answers
6
active
oldest
votes
The old-style backquotes ` `
do treat backslashes and nesting a bit different. The new-style $()
interprets everything in between ( )
as a command.
echo $(uname | $(echo cat))
Linux
echo `uname | `echo cat``
bash: command substitution: line 2: syntax error: unexpected end of file
echo cat
works if the nested backquotes are escaped:
echo `uname | `echo cat``
Linux
backslash fun:
echo $(echo '\')
\
echo `echo '\'`
The new-style $()
applies to all POSIX-conformant shells.
As mouviciel pointed out, old-style ` `
might be necessary for older shells.
Apart from the technical point of view, the old-style ` `
has also a visual disadvantage:
- Hard to notice:
I like $(program) better than `program`
- Easily confused with a single quote:
'`'`''`''`'`''`'
- Not so easy to type (maybe not even on the standard layout of the keyboard)
(and SE uses ` `
for own purpose, it was a pain writing this answer :)
8
The only thing I would add, is that I call '(' a paren, not a bracket (which is '[').
– Kendall Helmstetter Gelner
Jan 13 '11 at 18:09
@Kendall: and here I thought '{' was the left bracket for all those years...
– SamB
Jan 13 '11 at 20:32
4
@Sam:{ }
is usually called "curly brackets" or "braces" en.wikipedia.org/wiki/Braces_(punctuation)#Braces
– Jørn Schou-Rode
Jan 13 '11 at 21:35
I also refer to '{' as curly braces. Though it seems odd you need to add the qualifier "curly" if you call the other things brackets... I guess it's just because they actually curl.
– Kendall Helmstetter Gelner
Jan 14 '11 at 4:23
1
@slim I don't know on US/UK keyboards, but on spanish keyboards`
is a dead key, so I have to type either a double-backtick (something I usually forget I can even do) or backtick then space, which is a pain.
– Darkhogg
Apr 4 '14 at 16:39
|
show 6 more comments
Obvious difference I observe is that you cannot nest backticks while you can nest $()
. Maybe both exist for legacy reasons. Similarly, the .
and source
commands are synonyms.
9
Some Bourne-derived shells don't recognizesource
. Dash is one example.
– Dennis Williamson
Jan 13 '11 at 16:40
13
That's not true. You can nest backtick to any level, just more painfully. Note that both$(...)
and`...`
are standard (the latter being deprecated) while.
is standard but notsource
– Stéphane Chazelas
Oct 25 '12 at 10:17
2
Correction, only in(t)csh
can they not be nested.(t)csh
don't support$(...)
though. They do supportsource
(and not.
) though.
– Stéphane Chazelas
Aug 1 '14 at 12:28
add a comment |
$()
does not work with old Bourne shell. But it has been years since I worked with old Bourne shell.
add a comment |
Another note, $()
will use more system resource than using backticks, but is slightly faster.
In Mastering Unix shell scripting, Randal K. Michael had done a test in a chapter named "24 Ways to Process a File Line-by-Line".
1
This claim is nonsense. There is no reason why it should be faster as it is just using a different notation for the parser.
– schily
Sep 6 '15 at 13:17
@schily: Maybe, I only quote from the book, you can read it for more details.
– cuonglm
Sep 6 '15 at 15:19
2
I would tend to agree with @schily...why would it take more resources?
– Wildcard
Mar 7 '16 at 23:21
2
@Wildcard, I suppose it's because$()
makes your script one byte bigger than if it used`
(assuming you don't nest them and don't use backslashes within). As to which would be faster to parse, that would vary between shells and would be irrelevant as negligible compared to the cost of creating a pipe and forking of process which command substitution entails.
– Stéphane Chazelas
Dec 2 '16 at 9:45
add a comment |
To add to what others said here, you can use the backticks to simulate inline comments:
echo foo `# I'm a comment!` bar
The output is: foo bar
.
See the following for more information: https://stackoverflow.com/a/12797512 (Note also the comments below that post.)
add a comment |
The $()
syntax will not work with the old bourne shell.
With newer shells ` `
and $()
are equivalent but $()
is much more convenient to use when you need to nest multiple commands.
For instance :
echo $(basename $(dirname $(dirname /var/adm/sw/save )))
is easier to type and debug than :
echo `basename `dirname \`dirname /var/adm/sw/save \```
1
While $() may look nice, it is a pain when implementing a related parser because it requires a dual recursive parser.
– schily
Sep 6 '15 at 13:18
5
@schily On the other side, what would be a shell without a good parser.
– Emmanuel
Sep 8 '15 at 15:58
1
The problem is that you need to know where the string ends before you call the parser. This is relatively simple with the backticks, but it is hard with brackets as they are used for various purposes in the shell. So you need the parser twice and in a way that does not exist in the Bourne Shell.
– schily
Sep 8 '15 at 20:04
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f5778%2fwhats-the-difference-between-stuff-and-stuff%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
The old-style backquotes ` `
do treat backslashes and nesting a bit different. The new-style $()
interprets everything in between ( )
as a command.
echo $(uname | $(echo cat))
Linux
echo `uname | `echo cat``
bash: command substitution: line 2: syntax error: unexpected end of file
echo cat
works if the nested backquotes are escaped:
echo `uname | `echo cat``
Linux
backslash fun:
echo $(echo '\')
\
echo `echo '\'`
The new-style $()
applies to all POSIX-conformant shells.
As mouviciel pointed out, old-style ` `
might be necessary for older shells.
Apart from the technical point of view, the old-style ` `
has also a visual disadvantage:
- Hard to notice:
I like $(program) better than `program`
- Easily confused with a single quote:
'`'`''`''`'`''`'
- Not so easy to type (maybe not even on the standard layout of the keyboard)
(and SE uses ` `
for own purpose, it was a pain writing this answer :)
8
The only thing I would add, is that I call '(' a paren, not a bracket (which is '[').
– Kendall Helmstetter Gelner
Jan 13 '11 at 18:09
@Kendall: and here I thought '{' was the left bracket for all those years...
– SamB
Jan 13 '11 at 20:32
4
@Sam:{ }
is usually called "curly brackets" or "braces" en.wikipedia.org/wiki/Braces_(punctuation)#Braces
– Jørn Schou-Rode
Jan 13 '11 at 21:35
I also refer to '{' as curly braces. Though it seems odd you need to add the qualifier "curly" if you call the other things brackets... I guess it's just because they actually curl.
– Kendall Helmstetter Gelner
Jan 14 '11 at 4:23
1
@slim I don't know on US/UK keyboards, but on spanish keyboards`
is a dead key, so I have to type either a double-backtick (something I usually forget I can even do) or backtick then space, which is a pain.
– Darkhogg
Apr 4 '14 at 16:39
|
show 6 more comments
The old-style backquotes ` `
do treat backslashes and nesting a bit different. The new-style $()
interprets everything in between ( )
as a command.
echo $(uname | $(echo cat))
Linux
echo `uname | `echo cat``
bash: command substitution: line 2: syntax error: unexpected end of file
echo cat
works if the nested backquotes are escaped:
echo `uname | `echo cat``
Linux
backslash fun:
echo $(echo '\')
\
echo `echo '\'`
The new-style $()
applies to all POSIX-conformant shells.
As mouviciel pointed out, old-style ` `
might be necessary for older shells.
Apart from the technical point of view, the old-style ` `
has also a visual disadvantage:
- Hard to notice:
I like $(program) better than `program`
- Easily confused with a single quote:
'`'`''`''`'`''`'
- Not so easy to type (maybe not even on the standard layout of the keyboard)
(and SE uses ` `
for own purpose, it was a pain writing this answer :)
8
The only thing I would add, is that I call '(' a paren, not a bracket (which is '[').
– Kendall Helmstetter Gelner
Jan 13 '11 at 18:09
@Kendall: and here I thought '{' was the left bracket for all those years...
– SamB
Jan 13 '11 at 20:32
4
@Sam:{ }
is usually called "curly brackets" or "braces" en.wikipedia.org/wiki/Braces_(punctuation)#Braces
– Jørn Schou-Rode
Jan 13 '11 at 21:35
I also refer to '{' as curly braces. Though it seems odd you need to add the qualifier "curly" if you call the other things brackets... I guess it's just because they actually curl.
– Kendall Helmstetter Gelner
Jan 14 '11 at 4:23
1
@slim I don't know on US/UK keyboards, but on spanish keyboards`
is a dead key, so I have to type either a double-backtick (something I usually forget I can even do) or backtick then space, which is a pain.
– Darkhogg
Apr 4 '14 at 16:39
|
show 6 more comments
The old-style backquotes ` `
do treat backslashes and nesting a bit different. The new-style $()
interprets everything in between ( )
as a command.
echo $(uname | $(echo cat))
Linux
echo `uname | `echo cat``
bash: command substitution: line 2: syntax error: unexpected end of file
echo cat
works if the nested backquotes are escaped:
echo `uname | `echo cat``
Linux
backslash fun:
echo $(echo '\')
\
echo `echo '\'`
The new-style $()
applies to all POSIX-conformant shells.
As mouviciel pointed out, old-style ` `
might be necessary for older shells.
Apart from the technical point of view, the old-style ` `
has also a visual disadvantage:
- Hard to notice:
I like $(program) better than `program`
- Easily confused with a single quote:
'`'`''`''`'`''`'
- Not so easy to type (maybe not even on the standard layout of the keyboard)
(and SE uses ` `
for own purpose, it was a pain writing this answer :)
The old-style backquotes ` `
do treat backslashes and nesting a bit different. The new-style $()
interprets everything in between ( )
as a command.
echo $(uname | $(echo cat))
Linux
echo `uname | `echo cat``
bash: command substitution: line 2: syntax error: unexpected end of file
echo cat
works if the nested backquotes are escaped:
echo `uname | `echo cat``
Linux
backslash fun:
echo $(echo '\')
\
echo `echo '\'`
The new-style $()
applies to all POSIX-conformant shells.
As mouviciel pointed out, old-style ` `
might be necessary for older shells.
Apart from the technical point of view, the old-style ` `
has also a visual disadvantage:
- Hard to notice:
I like $(program) better than `program`
- Easily confused with a single quote:
'`'`''`''`'`''`'
- Not so easy to type (maybe not even on the standard layout of the keyboard)
(and SE uses ` `
for own purpose, it was a pain writing this answer :)
edited Apr 13 '17 at 12:36
Community♦
1
1
answered Jan 13 '11 at 11:30
wagwag
25.9k65548
25.9k65548
8
The only thing I would add, is that I call '(' a paren, not a bracket (which is '[').
– Kendall Helmstetter Gelner
Jan 13 '11 at 18:09
@Kendall: and here I thought '{' was the left bracket for all those years...
– SamB
Jan 13 '11 at 20:32
4
@Sam:{ }
is usually called "curly brackets" or "braces" en.wikipedia.org/wiki/Braces_(punctuation)#Braces
– Jørn Schou-Rode
Jan 13 '11 at 21:35
I also refer to '{' as curly braces. Though it seems odd you need to add the qualifier "curly" if you call the other things brackets... I guess it's just because they actually curl.
– Kendall Helmstetter Gelner
Jan 14 '11 at 4:23
1
@slim I don't know on US/UK keyboards, but on spanish keyboards`
is a dead key, so I have to type either a double-backtick (something I usually forget I can even do) or backtick then space, which is a pain.
– Darkhogg
Apr 4 '14 at 16:39
|
show 6 more comments
8
The only thing I would add, is that I call '(' a paren, not a bracket (which is '[').
– Kendall Helmstetter Gelner
Jan 13 '11 at 18:09
@Kendall: and here I thought '{' was the left bracket for all those years...
– SamB
Jan 13 '11 at 20:32
4
@Sam:{ }
is usually called "curly brackets" or "braces" en.wikipedia.org/wiki/Braces_(punctuation)#Braces
– Jørn Schou-Rode
Jan 13 '11 at 21:35
I also refer to '{' as curly braces. Though it seems odd you need to add the qualifier "curly" if you call the other things brackets... I guess it's just because they actually curl.
– Kendall Helmstetter Gelner
Jan 14 '11 at 4:23
1
@slim I don't know on US/UK keyboards, but on spanish keyboards`
is a dead key, so I have to type either a double-backtick (something I usually forget I can even do) or backtick then space, which is a pain.
– Darkhogg
Apr 4 '14 at 16:39
8
8
The only thing I would add, is that I call '(' a paren, not a bracket (which is '[').
– Kendall Helmstetter Gelner
Jan 13 '11 at 18:09
The only thing I would add, is that I call '(' a paren, not a bracket (which is '[').
– Kendall Helmstetter Gelner
Jan 13 '11 at 18:09
@Kendall: and here I thought '{' was the left bracket for all those years...
– SamB
Jan 13 '11 at 20:32
@Kendall: and here I thought '{' was the left bracket for all those years...
– SamB
Jan 13 '11 at 20:32
4
4
@Sam:
{ }
is usually called "curly brackets" or "braces" en.wikipedia.org/wiki/Braces_(punctuation)#Braces– Jørn Schou-Rode
Jan 13 '11 at 21:35
@Sam:
{ }
is usually called "curly brackets" or "braces" en.wikipedia.org/wiki/Braces_(punctuation)#Braces– Jørn Schou-Rode
Jan 13 '11 at 21:35
I also refer to '{' as curly braces. Though it seems odd you need to add the qualifier "curly" if you call the other things brackets... I guess it's just because they actually curl.
– Kendall Helmstetter Gelner
Jan 14 '11 at 4:23
I also refer to '{' as curly braces. Though it seems odd you need to add the qualifier "curly" if you call the other things brackets... I guess it's just because they actually curl.
– Kendall Helmstetter Gelner
Jan 14 '11 at 4:23
1
1
@slim I don't know on US/UK keyboards, but on spanish keyboards
`
is a dead key, so I have to type either a double-backtick (something I usually forget I can even do) or backtick then space, which is a pain.– Darkhogg
Apr 4 '14 at 16:39
@slim I don't know on US/UK keyboards, but on spanish keyboards
`
is a dead key, so I have to type either a double-backtick (something I usually forget I can even do) or backtick then space, which is a pain.– Darkhogg
Apr 4 '14 at 16:39
|
show 6 more comments
Obvious difference I observe is that you cannot nest backticks while you can nest $()
. Maybe both exist for legacy reasons. Similarly, the .
and source
commands are synonyms.
9
Some Bourne-derived shells don't recognizesource
. Dash is one example.
– Dennis Williamson
Jan 13 '11 at 16:40
13
That's not true. You can nest backtick to any level, just more painfully. Note that both$(...)
and`...`
are standard (the latter being deprecated) while.
is standard but notsource
– Stéphane Chazelas
Oct 25 '12 at 10:17
2
Correction, only in(t)csh
can they not be nested.(t)csh
don't support$(...)
though. They do supportsource
(and not.
) though.
– Stéphane Chazelas
Aug 1 '14 at 12:28
add a comment |
Obvious difference I observe is that you cannot nest backticks while you can nest $()
. Maybe both exist for legacy reasons. Similarly, the .
and source
commands are synonyms.
9
Some Bourne-derived shells don't recognizesource
. Dash is one example.
– Dennis Williamson
Jan 13 '11 at 16:40
13
That's not true. You can nest backtick to any level, just more painfully. Note that both$(...)
and`...`
are standard (the latter being deprecated) while.
is standard but notsource
– Stéphane Chazelas
Oct 25 '12 at 10:17
2
Correction, only in(t)csh
can they not be nested.(t)csh
don't support$(...)
though. They do supportsource
(and not.
) though.
– Stéphane Chazelas
Aug 1 '14 at 12:28
add a comment |
Obvious difference I observe is that you cannot nest backticks while you can nest $()
. Maybe both exist for legacy reasons. Similarly, the .
and source
commands are synonyms.
Obvious difference I observe is that you cannot nest backticks while you can nest $()
. Maybe both exist for legacy reasons. Similarly, the .
and source
commands are synonyms.
edited Nov 3 '12 at 10:28
Tshepang
26.8k72188267
26.8k72188267
answered Jan 13 '11 at 11:17
balkibalki
2,15842038
2,15842038
9
Some Bourne-derived shells don't recognizesource
. Dash is one example.
– Dennis Williamson
Jan 13 '11 at 16:40
13
That's not true. You can nest backtick to any level, just more painfully. Note that both$(...)
and`...`
are standard (the latter being deprecated) while.
is standard but notsource
– Stéphane Chazelas
Oct 25 '12 at 10:17
2
Correction, only in(t)csh
can they not be nested.(t)csh
don't support$(...)
though. They do supportsource
(and not.
) though.
– Stéphane Chazelas
Aug 1 '14 at 12:28
add a comment |
9
Some Bourne-derived shells don't recognizesource
. Dash is one example.
– Dennis Williamson
Jan 13 '11 at 16:40
13
That's not true. You can nest backtick to any level, just more painfully. Note that both$(...)
and`...`
are standard (the latter being deprecated) while.
is standard but notsource
– Stéphane Chazelas
Oct 25 '12 at 10:17
2
Correction, only in(t)csh
can they not be nested.(t)csh
don't support$(...)
though. They do supportsource
(and not.
) though.
– Stéphane Chazelas
Aug 1 '14 at 12:28
9
9
Some Bourne-derived shells don't recognize
source
. Dash is one example.– Dennis Williamson
Jan 13 '11 at 16:40
Some Bourne-derived shells don't recognize
source
. Dash is one example.– Dennis Williamson
Jan 13 '11 at 16:40
13
13
That's not true. You can nest backtick to any level, just more painfully. Note that both
$(...)
and `...`
are standard (the latter being deprecated) while .
is standard but not source
– Stéphane Chazelas
Oct 25 '12 at 10:17
That's not true. You can nest backtick to any level, just more painfully. Note that both
$(...)
and `...`
are standard (the latter being deprecated) while .
is standard but not source
– Stéphane Chazelas
Oct 25 '12 at 10:17
2
2
Correction, only in
(t)csh
can they not be nested. (t)csh
don't support $(...)
though. They do support source
(and not .
) though.– Stéphane Chazelas
Aug 1 '14 at 12:28
Correction, only in
(t)csh
can they not be nested. (t)csh
don't support $(...)
though. They do support source
(and not .
) though.– Stéphane Chazelas
Aug 1 '14 at 12:28
add a comment |
$()
does not work with old Bourne shell. But it has been years since I worked with old Bourne shell.
add a comment |
$()
does not work with old Bourne shell. But it has been years since I worked with old Bourne shell.
add a comment |
$()
does not work with old Bourne shell. But it has been years since I worked with old Bourne shell.
$()
does not work with old Bourne shell. But it has been years since I worked with old Bourne shell.
answered Jan 13 '11 at 14:38
mouvicielmouviciel
1,1951012
1,1951012
add a comment |
add a comment |
Another note, $()
will use more system resource than using backticks, but is slightly faster.
In Mastering Unix shell scripting, Randal K. Michael had done a test in a chapter named "24 Ways to Process a File Line-by-Line".
1
This claim is nonsense. There is no reason why it should be faster as it is just using a different notation for the parser.
– schily
Sep 6 '15 at 13:17
@schily: Maybe, I only quote from the book, you can read it for more details.
– cuonglm
Sep 6 '15 at 15:19
2
I would tend to agree with @schily...why would it take more resources?
– Wildcard
Mar 7 '16 at 23:21
2
@Wildcard, I suppose it's because$()
makes your script one byte bigger than if it used`
(assuming you don't nest them and don't use backslashes within). As to which would be faster to parse, that would vary between shells and would be irrelevant as negligible compared to the cost of creating a pipe and forking of process which command substitution entails.
– Stéphane Chazelas
Dec 2 '16 at 9:45
add a comment |
Another note, $()
will use more system resource than using backticks, but is slightly faster.
In Mastering Unix shell scripting, Randal K. Michael had done a test in a chapter named "24 Ways to Process a File Line-by-Line".
1
This claim is nonsense. There is no reason why it should be faster as it is just using a different notation for the parser.
– schily
Sep 6 '15 at 13:17
@schily: Maybe, I only quote from the book, you can read it for more details.
– cuonglm
Sep 6 '15 at 15:19
2
I would tend to agree with @schily...why would it take more resources?
– Wildcard
Mar 7 '16 at 23:21
2
@Wildcard, I suppose it's because$()
makes your script one byte bigger than if it used`
(assuming you don't nest them and don't use backslashes within). As to which would be faster to parse, that would vary between shells and would be irrelevant as negligible compared to the cost of creating a pipe and forking of process which command substitution entails.
– Stéphane Chazelas
Dec 2 '16 at 9:45
add a comment |
Another note, $()
will use more system resource than using backticks, but is slightly faster.
In Mastering Unix shell scripting, Randal K. Michael had done a test in a chapter named "24 Ways to Process a File Line-by-Line".
Another note, $()
will use more system resource than using backticks, but is slightly faster.
In Mastering Unix shell scripting, Randal K. Michael had done a test in a chapter named "24 Ways to Process a File Line-by-Line".
edited Jun 9 '13 at 9:25
Tshepang
26.8k72188267
26.8k72188267
answered Jun 7 '13 at 19:43
cuonglmcuonglm
107k25215314
107k25215314
1
This claim is nonsense. There is no reason why it should be faster as it is just using a different notation for the parser.
– schily
Sep 6 '15 at 13:17
@schily: Maybe, I only quote from the book, you can read it for more details.
– cuonglm
Sep 6 '15 at 15:19
2
I would tend to agree with @schily...why would it take more resources?
– Wildcard
Mar 7 '16 at 23:21
2
@Wildcard, I suppose it's because$()
makes your script one byte bigger than if it used`
(assuming you don't nest them and don't use backslashes within). As to which would be faster to parse, that would vary between shells and would be irrelevant as negligible compared to the cost of creating a pipe and forking of process which command substitution entails.
– Stéphane Chazelas
Dec 2 '16 at 9:45
add a comment |
1
This claim is nonsense. There is no reason why it should be faster as it is just using a different notation for the parser.
– schily
Sep 6 '15 at 13:17
@schily: Maybe, I only quote from the book, you can read it for more details.
– cuonglm
Sep 6 '15 at 15:19
2
I would tend to agree with @schily...why would it take more resources?
– Wildcard
Mar 7 '16 at 23:21
2
@Wildcard, I suppose it's because$()
makes your script one byte bigger than if it used`
(assuming you don't nest them and don't use backslashes within). As to which would be faster to parse, that would vary between shells and would be irrelevant as negligible compared to the cost of creating a pipe and forking of process which command substitution entails.
– Stéphane Chazelas
Dec 2 '16 at 9:45
1
1
This claim is nonsense. There is no reason why it should be faster as it is just using a different notation for the parser.
– schily
Sep 6 '15 at 13:17
This claim is nonsense. There is no reason why it should be faster as it is just using a different notation for the parser.
– schily
Sep 6 '15 at 13:17
@schily: Maybe, I only quote from the book, you can read it for more details.
– cuonglm
Sep 6 '15 at 15:19
@schily: Maybe, I only quote from the book, you can read it for more details.
– cuonglm
Sep 6 '15 at 15:19
2
2
I would tend to agree with @schily...why would it take more resources?
– Wildcard
Mar 7 '16 at 23:21
I would tend to agree with @schily...why would it take more resources?
– Wildcard
Mar 7 '16 at 23:21
2
2
@Wildcard, I suppose it's because
$()
makes your script one byte bigger than if it used `
(assuming you don't nest them and don't use backslashes within). As to which would be faster to parse, that would vary between shells and would be irrelevant as negligible compared to the cost of creating a pipe and forking of process which command substitution entails.– Stéphane Chazelas
Dec 2 '16 at 9:45
@Wildcard, I suppose it's because
$()
makes your script one byte bigger than if it used `
(assuming you don't nest them and don't use backslashes within). As to which would be faster to parse, that would vary between shells and would be irrelevant as negligible compared to the cost of creating a pipe and forking of process which command substitution entails.– Stéphane Chazelas
Dec 2 '16 at 9:45
add a comment |
To add to what others said here, you can use the backticks to simulate inline comments:
echo foo `# I'm a comment!` bar
The output is: foo bar
.
See the following for more information: https://stackoverflow.com/a/12797512 (Note also the comments below that post.)
add a comment |
To add to what others said here, you can use the backticks to simulate inline comments:
echo foo `# I'm a comment!` bar
The output is: foo bar
.
See the following for more information: https://stackoverflow.com/a/12797512 (Note also the comments below that post.)
add a comment |
To add to what others said here, you can use the backticks to simulate inline comments:
echo foo `# I'm a comment!` bar
The output is: foo bar
.
See the following for more information: https://stackoverflow.com/a/12797512 (Note also the comments below that post.)
To add to what others said here, you can use the backticks to simulate inline comments:
echo foo `# I'm a comment!` bar
The output is: foo bar
.
See the following for more information: https://stackoverflow.com/a/12797512 (Note also the comments below that post.)
edited May 23 '17 at 12:40
Community♦
1
1
answered Dec 2 '16 at 9:31
phkphk
4,11952257
4,11952257
add a comment |
add a comment |
The $()
syntax will not work with the old bourne shell.
With newer shells ` `
and $()
are equivalent but $()
is much more convenient to use when you need to nest multiple commands.
For instance :
echo $(basename $(dirname $(dirname /var/adm/sw/save )))
is easier to type and debug than :
echo `basename `dirname \`dirname /var/adm/sw/save \```
1
While $() may look nice, it is a pain when implementing a related parser because it requires a dual recursive parser.
– schily
Sep 6 '15 at 13:18
5
@schily On the other side, what would be a shell without a good parser.
– Emmanuel
Sep 8 '15 at 15:58
1
The problem is that you need to know where the string ends before you call the parser. This is relatively simple with the backticks, but it is hard with brackets as they are used for various purposes in the shell. So you need the parser twice and in a way that does not exist in the Bourne Shell.
– schily
Sep 8 '15 at 20:04
add a comment |
The $()
syntax will not work with the old bourne shell.
With newer shells ` `
and $()
are equivalent but $()
is much more convenient to use when you need to nest multiple commands.
For instance :
echo $(basename $(dirname $(dirname /var/adm/sw/save )))
is easier to type and debug than :
echo `basename `dirname \`dirname /var/adm/sw/save \```
1
While $() may look nice, it is a pain when implementing a related parser because it requires a dual recursive parser.
– schily
Sep 6 '15 at 13:18
5
@schily On the other side, what would be a shell without a good parser.
– Emmanuel
Sep 8 '15 at 15:58
1
The problem is that you need to know where the string ends before you call the parser. This is relatively simple with the backticks, but it is hard with brackets as they are used for various purposes in the shell. So you need the parser twice and in a way that does not exist in the Bourne Shell.
– schily
Sep 8 '15 at 20:04
add a comment |
The $()
syntax will not work with the old bourne shell.
With newer shells ` `
and $()
are equivalent but $()
is much more convenient to use when you need to nest multiple commands.
For instance :
echo $(basename $(dirname $(dirname /var/adm/sw/save )))
is easier to type and debug than :
echo `basename `dirname \`dirname /var/adm/sw/save \```
The $()
syntax will not work with the old bourne shell.
With newer shells ` `
and $()
are equivalent but $()
is much more convenient to use when you need to nest multiple commands.
For instance :
echo $(basename $(dirname $(dirname /var/adm/sw/save )))
is easier to type and debug than :
echo `basename `dirname \`dirname /var/adm/sw/save \```
edited Jan 18 '15 at 14:25
Axel Beckert
241112
241112
answered Feb 19 '14 at 12:36
EmmanuelEmmanuel
3,12411222
3,12411222
1
While $() may look nice, it is a pain when implementing a related parser because it requires a dual recursive parser.
– schily
Sep 6 '15 at 13:18
5
@schily On the other side, what would be a shell without a good parser.
– Emmanuel
Sep 8 '15 at 15:58
1
The problem is that you need to know where the string ends before you call the parser. This is relatively simple with the backticks, but it is hard with brackets as they are used for various purposes in the shell. So you need the parser twice and in a way that does not exist in the Bourne Shell.
– schily
Sep 8 '15 at 20:04
add a comment |
1
While $() may look nice, it is a pain when implementing a related parser because it requires a dual recursive parser.
– schily
Sep 6 '15 at 13:18
5
@schily On the other side, what would be a shell without a good parser.
– Emmanuel
Sep 8 '15 at 15:58
1
The problem is that you need to know where the string ends before you call the parser. This is relatively simple with the backticks, but it is hard with brackets as they are used for various purposes in the shell. So you need the parser twice and in a way that does not exist in the Bourne Shell.
– schily
Sep 8 '15 at 20:04
1
1
While $() may look nice, it is a pain when implementing a related parser because it requires a dual recursive parser.
– schily
Sep 6 '15 at 13:18
While $() may look nice, it is a pain when implementing a related parser because it requires a dual recursive parser.
– schily
Sep 6 '15 at 13:18
5
5
@schily On the other side, what would be a shell without a good parser.
– Emmanuel
Sep 8 '15 at 15:58
@schily On the other side, what would be a shell without a good parser.
– Emmanuel
Sep 8 '15 at 15:58
1
1
The problem is that you need to know where the string ends before you call the parser. This is relatively simple with the backticks, but it is hard with brackets as they are used for various purposes in the shell. So you need the parser twice and in a way that does not exist in the Bourne Shell.
– schily
Sep 8 '15 at 20:04
The problem is that you need to know where the string ends before you call the parser. This is relatively simple with the backticks, but it is hard with brackets as they are used for various purposes in the shell. So you need the parser twice and in a way that does not exist in the Bourne Shell.
– schily
Sep 8 '15 at 20:04
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f5778%2fwhats-the-difference-between-stuff-and-stuff%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
18
See also: BashFAQ/082.
– Dennis Williamson
Jan 13 '11 at 16:38
40
For a second there I thought this was a jQuery question.
– David Murdoch
Jan 13 '11 at 20:42
The result might depend on the shell - some support both.
– artdanil
Feb 15 '11 at 22:33