Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Addition to the accepted answer:

While I generally agree with @l0b0's answer here, I suspect the placement of bare backticks in the "worst to best" list is at least partly a result of the assumption that $(...) is available everywhere. I realize that the question specifies Bash, but there are plenty of times when Bash turns out to mean /bin/sh, which may not always actually be the full Bourne Again shell.

In particular, the plain Bourne shell won't know what to do with $(...), so scripts which claim to be compatible with it (e.g., via a #!/bin/sh shebang line) will likely misbehave if they are actually run by the "real" /bin/sh – this is of special interest when, say, producing init scripts, or packaging pre- and post-scripts, and can land one in a surprising place during installation of a base system.

If any of that sounds like something you're planning to do with this variable, nesting is probably less of a concern than having the script actually, predictably run. When it's a simple enough case and portability is a concern, even if I expect the script to usually run on systems where /bin/sh is Bash, I often tend to use backticks for this reason, with multiple assignments instead of nesting.

Having said all that, the ubiquity of shells which implement $(...) (Bash, Dash, et al.), leaves us in a good spot to stick with the prettier, easier-to-nest, and more recently preferred POSIX syntax in most cases, for all the reasons @l0b0 mentions.

Aside: this has shown up occasionally on StackOverflow, too –

Addition to the accepted answer:

While I generally agree with @l0b0's answer here, I suspect the placement of bare backticks in the "worst to best" list is at least partly a result of the assumption that $(...) is available everywhere. I realize that the question specifies Bash, but there are plenty of times when Bash turns out to mean /bin/sh, which may not always actually be the full Bourne Again shell.

In particular, the plain Bourne shell won't know what to do with $(...), so scripts which claim to be compatible with it (e.g., via a #!/bin/sh shebang line) will likely misbehave if they are actually run by the "real" /bin/sh – this is of special interest when, say, producing init scripts, or packaging pre- and post-scripts, and can land one in a surprising place during installation of a base system.

If any of that sounds like something you're planning to do with this variable, nesting is probably less of a concern than having the script actually, predictably run. When it's a simple enough case and portability is a concern, even if I expect the script to usually run on systems where /bin/sh is Bash, I often tend to use backticks for this reason, with multiple assignments instead of nesting.

Having said all that, the ubiquity of shells which implement $(...) (Bash, Dash, et al.), leaves us in a good spot to stick with the prettier, easier-to-nest, and more recently preferred POSIX syntax in most cases, for all the reasons @l0b0 mentions.

Aside: this has shown up occasionally on StackOverflow, too –

Addition to the accepted answer:

While I generally agree with @l0b0's answer here, I suspect the placement of bare backticks in the "worst to best" list is at least partly a result of the assumption that $(...) is available everywhere. I realize that the question specifies Bash, but there are plenty of times when Bash turns out to mean /bin/sh, which may not always actually be the full Bourne Again shell.

In particular, the plain Bourne shell won't know what to do with $(...), so scripts which claim to be compatible with it (e.g., via a #!/bin/sh shebang line) will likely misbehave if they are actually run by the "real" /bin/sh – this is of special interest when, say, producing init scripts, or packaging pre- and post-scripts, and can land one in a surprising place during installation of a base system.

If any of that sounds like something you're planning to do with this variable, nesting is probably less of a concern than having the script actually, predictably run. When it's a simple enough case and portability is a concern, even if I expect the script to usually run on systems where /bin/sh is Bash, I often tend to use backticks for this reason, with multiple assignments instead of nesting.

Having said all that, the ubiquity of shells which implement $(...) (Bash, Dash, et al.), leaves us in a good spot to stick with the prettier, easier-to-nest, and more recently preferred POSIX syntax in most cases, for all the reasons @l0b0 mentions.

Aside: this has shown up occasionally on StackOverflow, too –

replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link

Addition to the accepted answer:

While I generally agree with @l0b0's answer@l0b0's answer here, I suspect the placement of bare backticks in the "worst to best" list is at least partly a result of the assumption that $(...) is available everywhere. I realize that the question specifies Bash, but there are plenty of times when Bash turns out to mean /bin/sh, which may not always actually be the full Bourne Again shell.

In particular, the plain Bourne shell won't know what to do with $(...), so scripts which claim to be compatible with it (e.g., via a #!/bin/sh shebang line) will likely misbehave if they are actually run by the "real" /bin/sh – this is of special interest when, say, producing init scripts, or packaging pre- and post-scripts, and can land one in a surprising place during installation of a base system.

If any of that sounds like something you're planning to do with this variable, nesting is probably less of a concern than having the script actually, predictably run. When it's a simple enough case and portability is a concern, even if I expect the script to usually run on systems where /bin/sh is Bash, I often tend to use backticks for this reason, with multiple assignments instead of nesting.

Having said all that, the ubiquity of shells which implement $(...) (Bash, Dash, et al.), leaves us in a good spot to stick with the prettier, easier-to-nest, and more recently preferred POSIX syntax in most cases, for all the reasons @l0b0 mentions.

Aside: this has shown up occasionally on StackOverflow, too –

Addition to the accepted answer:

While I generally agree with @l0b0's answer here, I suspect the placement of bare backticks in the "worst to best" list is at least partly a result of the assumption that $(...) is available everywhere. I realize that the question specifies Bash, but there are plenty of times when Bash turns out to mean /bin/sh, which may not always actually be the full Bourne Again shell.

In particular, the plain Bourne shell won't know what to do with $(...), so scripts which claim to be compatible with it (e.g., via a #!/bin/sh shebang line) will likely misbehave if they are actually run by the "real" /bin/sh – this is of special interest when, say, producing init scripts, or packaging pre- and post-scripts, and can land one in a surprising place during installation of a base system.

If any of that sounds like something you're planning to do with this variable, nesting is probably less of a concern than having the script actually, predictably run. When it's a simple enough case and portability is a concern, even if I expect the script to usually run on systems where /bin/sh is Bash, I often tend to use backticks for this reason, with multiple assignments instead of nesting.

Having said all that, the ubiquity of shells which implement $(...) (Bash, Dash, et al.), leaves us in a good spot to stick with the prettier, easier-to-nest, and more recently preferred POSIX syntax in most cases, for all the reasons @l0b0 mentions.

Aside: this has shown up occasionally on StackOverflow, too –

Addition to the accepted answer:

While I generally agree with @l0b0's answer here, I suspect the placement of bare backticks in the "worst to best" list is at least partly a result of the assumption that $(...) is available everywhere. I realize that the question specifies Bash, but there are plenty of times when Bash turns out to mean /bin/sh, which may not always actually be the full Bourne Again shell.

In particular, the plain Bourne shell won't know what to do with $(...), so scripts which claim to be compatible with it (e.g., via a #!/bin/sh shebang line) will likely misbehave if they are actually run by the "real" /bin/sh – this is of special interest when, say, producing init scripts, or packaging pre- and post-scripts, and can land one in a surprising place during installation of a base system.

If any of that sounds like something you're planning to do with this variable, nesting is probably less of a concern than having the script actually, predictably run. When it's a simple enough case and portability is a concern, even if I expect the script to usually run on systems where /bin/sh is Bash, I often tend to use backticks for this reason, with multiple assignments instead of nesting.

Having said all that, the ubiquity of shells which implement $(...) (Bash, Dash, et al.), leaves us in a good spot to stick with the prettier, easier-to-nest, and more recently preferred POSIX syntax in most cases, for all the reasons @l0b0 mentions.

Aside: this has shown up occasionally on StackOverflow, too –

...aaand apparently rep doesn't transfer from one StackExchange site to another. Oh well, here's the comment I would have liked to have added Addition to the accepted answer:

While I generally agree with @l0b0's answer here, I suspect the placement of bare backticks in the "worst to best" list is at least partly a result of the assumption that $(...) is available everywhere. I realize that the question specifies Bash, but there are plenty of times when Bash turns out to mean /bin/sh, which may not always actually be the full Bourne Again shell.

In particular, the plain Bourne shell won't know what to do with $(...), so scripts which claim to be compatible with it (e.g., via a #!/bin/sh shebang line) will likely misbehave if they are actually run by the "real" /bin/sh – this is of special interest when, say, producing init scripts, or packaging pre- and post-scripts, and can land one in a surprising place during installation of a base system.

If any of that sounds like something you're planning to do with this variable, nesting is probably less of a concern than having the script actually, predictably run. When it's a simple enough case and portability is a concern, even if I expect the script to usually run on systems where /bin/sh is Bash, I often tend to use backticks for this reason, with multiple assignments instead of nesting.

Having said all that, the ubiquity of shells which implement $(...) (Bash, Dash, et al.), leaves us in a good spot to stick with the prettier, easier-to-nest, and more recently preferred POSIX syntax in most cases, for all the reasons @l0b0 mentions.

Aside: this has shown up occasionally on StackOverflow, too –

...aaand apparently rep doesn't transfer from one StackExchange site to another. Oh well, here's the comment I would have liked to have added to the accepted answer:

While I generally agree with @l0b0's answer here, I suspect the placement of bare backticks in the "worst to best" list is at least partly a result of the assumption that $(...) is available everywhere. I realize that the question specifies Bash, but there are plenty of times when Bash turns out to mean /bin/sh, which may not always actually be the full Bourne Again shell.

In particular, the plain Bourne shell won't know what to do with $(...), so scripts which claim to be compatible with it (e.g., via a #!/bin/sh shebang line) will likely misbehave if they are actually run by the "real" /bin/sh – this is of special interest when, say, producing init scripts, or packaging pre- and post-scripts, and can land one in a surprising place during installation of a base system.

If any of that sounds like something you're planning to do with this variable, nesting is probably less of a concern than having the script actually, predictably run. When it's a simple enough case and portability is a concern, even if I expect the script to usually run on systems where /bin/sh is Bash, I often tend to use backticks for this reason, with multiple assignments instead of nesting.

Having said all that, the ubiquity of shells which implement $(...) (Bash, Dash, et al.), leaves us in a good spot to stick with the prettier, easier-to-nest, and more recently preferred POSIX syntax in most cases, for all the reasons @l0b0 mentions.

Aside: this has shown up occasionally on StackOverflow, too –

Addition to the accepted answer:

While I generally agree with @l0b0's answer here, I suspect the placement of bare backticks in the "worst to best" list is at least partly a result of the assumption that $(...) is available everywhere. I realize that the question specifies Bash, but there are plenty of times when Bash turns out to mean /bin/sh, which may not always actually be the full Bourne Again shell.

In particular, the plain Bourne shell won't know what to do with $(...), so scripts which claim to be compatible with it (e.g., via a #!/bin/sh shebang line) will likely misbehave if they are actually run by the "real" /bin/sh – this is of special interest when, say, producing init scripts, or packaging pre- and post-scripts, and can land one in a surprising place during installation of a base system.

If any of that sounds like something you're planning to do with this variable, nesting is probably less of a concern than having the script actually, predictably run. When it's a simple enough case and portability is a concern, even if I expect the script to usually run on systems where /bin/sh is Bash, I often tend to use backticks for this reason, with multiple assignments instead of nesting.

Having said all that, the ubiquity of shells which implement $(...) (Bash, Dash, et al.), leaves us in a good spot to stick with the prettier, easier-to-nest, and more recently preferred POSIX syntax in most cases, for all the reasons @l0b0 mentions.

Aside: this has shown up occasionally on StackOverflow, too –

Source Link
rsandwick3
  • 261
  • 2
  • 4
Loading