0

This question is regarding the Unix cp command.

What is the $(...) operator doing below?

cp $(bundle show bootstrap-sass)/vendor/assets/stylesheets/bootstrap.scss \ app/assets/stylesheets/bootstrap-custom.scss

I came across this notation from the page: https://github.com/twbs/bootstrap-sass#usage

I checked the man page for cp and did not see any references to this operation. I'm new to *nix. Thanks.

user3621156
  • 65
  • 1
  • 7

2 Answers2

3

In shell scripting, the $(...) executes the commands in the parenthesis and returns the text printed to STDOUT by that command. This also applies to the backtick notation as well.

For example: echo $(date) - This is a dated line will print something like Thu Jun 26 10:08:20 CDT 2014 - This is a dated line

Here's another Stack Overflow question on the topic.

Mr. Llama
  • 20,202
  • 2
  • 62
  • 115
  • Very clear. Thanks for the example. I'll accept your answer as soon as SO allows me to. – user3621156 Jun 26 '14 at 15:09
  • 1
    1 other point (of trivia ;-) ). This is known as `command-substitution`. You will often see another form of command-substitution that uses single back-tick characters (on each end) surround the cmd whose output is to be used. (Hard to illustrate in an S.O. comment). However, `$(...)` is the definitely preferred form, as back-ticks have been marked as deprecated in Kornshell since at least 1995. – shellter Jun 26 '14 at 15:31
  • @shellter - Absolutely! Unless you can't avoid it, the backtick version should be avoided. It's harder to read and much harder to nest. I think the question linked in the answer touches on this a bit. – Mr. Llama Jun 26 '14 at 15:35
  • @Mr.Llama: Yep! And Hey, I said hard to illustrate in S.O. comment, but just notice that O.P. has back-tics surrounding the `cp` cmd in the title! :-) . Unfortunately, `cp` doesn't return output to stdout, so not a good example of cmd-sub. ;-/ Good luck to all! – shellter Jun 26 '14 at 15:38
1

$() evaluate contents of brackets before the main command.

Igor
  • 33,276
  • 14
  • 79
  • 112
camelccc
  • 2,847
  • 8
  • 26
  • 52