Most of the time I see $(command) used, but I have also seen "$(command)" for example:  if [ "$(command)" ]; then     stuff fi   What is the purpose of the quotes in the second example?
1847
Or, an introductory guide to robust filename handling and other string passing in shell scripts.  I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some file names).  I encountered a problem such as the following:   I have a file name containing a space hello world, and it was treated as two separate files hello and world. I have an input line with two consecutive spaces and they shrank to one in the input. Leading and trailing whitespace disappears from input lines. Sometimes, when the input contains one of the characters \[*?, they are replaced by some text which is is actually the name of files. There is an apostrophe ' (or a double quote ") in the input and things got weird after that point. There is a backslash in the input (or: I am using Cygwin and some of my file names have Windows-style \ separators).   What is going on and how do I fix it?
89914
Examples  I've recently found examples of using pairs of enclosing braces {}, with nothing in between the opening and closing braces, as arguments to commands and even to their options:  cat foo | xargs -I{} echo {}  find . -size 0 -exec rm -i {} \;  No Documentation  My problem is that I cannot find a documentation in the  that describes the usage of {} in such context as in the examples above.  I do not think it is a , because a dollar sign must precede the enclosing braces in a parameter expansion as in ${}.  It cannot be a  either, because it takes the form of {x..y[..incr]}, where x and y are not optional.  It also cannot be a  either, because {} is used as arguments.  Questions   What does a pair of enclosing braces {} even mean, in general, as an argument to any command that accepts it? Where can I find a documentation that describes the usage of {} as arguments?
11938
Does the @ mean anything specific? For example, is it substituted? Does it split the command into parts, like \s@foo could internally mean "foo of type s"? Is the purpose of the @ only to make internal commands break when used outside a class definition or a package? If so, how is that a Good Thing?
43099
On the paragraph explaining arithmetic expansion,  uncovers 2 different ways of evaluating an expression, the first one uses $(( EXPRESSION )) and the second one uses $[ EXPRESSION ]. The two ways seem pretty similar as the only difference I have found is:     $[ EXPRESSION ] will only calculate the result of EXPRESSION, and do no tests:   Yet, I am intrigued because the same document recommends using $[ EXPRESSION ] rather than $(( EXPRESSION )).     Wherever possible, Bash users should try to use the syntax with square brackets:   Why would you want that if less tests are being done?
98525
In  my question () contains a "$" in a quoted section of the question.  Originally I had a second "$" in a second quoted  section of the same question.    However when I did this the second $ seemed to trigger a style that made the text italic and lost spacing between words.  I took out the second "$" and instead emphasized it with the word "dollars" which solved the immediate problem.  However, in the listing of the question, (not the question itself) the same thing happens after the first "$".  The summary shows the text without spaces between words and in italic.  Seems like a bug.  Below is a verbatim copy/paste of the original issue (two dollar signs):    I was able to find a small ESC for about $12 off of ebay.  If you were designing a robot, would you see that and think?       $12 bucks for an ESC that connects to simple pulse-wave interface -   sign me up!   Or would you think:     $12 just to control a motor? I could throw together an H-bridge for   $0.50 and be done with it.   My robot in particular actually has two motors and therefor $24 to control the two of them.  But the interface is really easy (plus has the added advantage of being R/C vs computer controlled with a simple change of connectors.  Which way would you go?
42231
One of my coworkers has provided me with a Bash syntax that I am unfamiliar with.  My Google foo has failed me on figuring out what it does and why/when I should use it.    The command that he sent me was of this form:  someVariable=something command   Initially, I thought that this was equivalent to the following:   someVariable=something ; command   Or  someVariable=something  command   But this doesn't appear to the be case.  Examples:   [Jan-03 11:26][~]$ # Look at the environment variable BAZ. It is currently empty [Jan-03 11:26][~]$ echo $BAZ  [Jan-03 11:27][~]$ # Try running a command of the same format     [Jan-03 11:27][~]$ BAZ=jake echo $BAZ  [Jan-03 11:27][~]$     [Jan-03 11:27][~]$ # Now, echo BAZ again. It is still empty:     [Jan-03 11:27][~]$ echo $BAZ  [Jan-03 11:27][~]$     [Jan-03 11:28][~]$     [Jan-03 11:28][~]$ # If we add a semi-colon to the command, we get dramatically different results: [Jan-03 11:28][~]$ BAZ=jake ; echo $BAZ jake [Jan-03 11:28][~]$ [Jan-03 11:28][~]$ # And we can see that the variable is actually set: [Jan-03 11:29][~]$ echo $BAZ jake [Jan-03 11:29][~]$   What does this syntax do?  What happens to the variable that has been set?  Why does this work?
88566
With this set of commands, what are the {} and \; characters for? find . -name '*.clj' -exec grep -r resources {} \;
84768
I'm used to type strings with quotation marks, but from now and then when I surf through config files and recommendations, I see apostrophes being used.  I often copy apostrophe things into my config files and substitute it with my quotation marks so that the code fits together.  But what is their difference? (I mostly target this for bash. If other Linux-based scripting does it different, that would be an extra.)  For example:  echo "Hello World!" and echo 'Hello World!'  Has it something to do that I maybe can't use (formatted) variables if I use one or the other, or is it simply personal preference?
55413
The question is pretty straight forward. I can get the exit code of the previous command by using $?. But what exactly is it?  I don't think it is a variable, because you can't have any special characters in the name of variable other than _.  foo?foo=10   will result in the error: foo?foo=10: command not found  So if it is not a variable, what is it? Are there others like it?
4371
This question is inspired by    I see these constructs  for file in `find . -type f -name ...`; do smth with ${file}; done   and  for dir in $(find . -type d -name ...); do smth with ${dir}; done   being used here almost on a daily basis even if some people take the time to comment on those posts explaining why this kind of stuff should be avoided... Seeing the number of such posts (and the fact that sometimes those comments are simply ignored) I thought I might as well ask a question:  Why is looping over find's output bad practice and what's the proper way to run one or more commands for each file name/path returned by find ?
23221
The modern recommendation is to use:  $(...)   instead of the older:  `...`   mainly for readability and to avoid the need for escaping when nesting.  Which shells do not support the $(...) form, and are any of them still in use today?
112122
Can anybody explain to me what the shell does in the two examples A) and B) below? It obviously behaves differently, but I can't find out why the output is different.  Example: Let's have a script in our current directory named bla.sh with only one command: echo ${0##/*} hello  A) Started as: ./bla.sh gives: ./bla.sh hello  B) Started as: . bla.sh gives: -bash hello  Since I use this in a script, the second output (because of the "-" in front of the -bash) kills the command. Of course, a simple -- before the ${...} helped, but I would love to understand what causes the output in the first place.I love bash. And vi[m]. But I digress…
69962
I have an application which takes as an input attributes in double quotes embedded in single quotes. Take for example this right command:  command -p 'cluster="cl1"'   In order to automate it, I created a bash file using $CLUSTER as a variable. How should be my command? In other words, what should I put instead of cl1?  Please note that, If I modified the above command, it won't be accepted. For instance: command -p "cluster=cl1" is not accepted
49040
for i in $(xrandr); do echo  "$i" ; done for i in "$(xrandr)"; do echo "$i"; done for i in "$(xrandr)"; do echo $i; done   I understand why 1 differs from 2. But why does 3 give a different output from 2? Please explain the output too. How do quotes work on newlines?
20273
As a primarily Java programmer, I find the bash if-then construct quite confusing, especially regarding whitespace. Can anyone explain why the first one works, but not the second or third?  #works if [ -n $1 ]; then echo "parameterized"; fi  #output: ./links: Zeile 1: [-n: Kommando nicht gefunden. if [-n $1 ]; then echo "parameterized"; fi  #output: ./links: Zeile 1: [: Fehlende `]' if [ -n $1]; then echo "parameterized"; fi
76187
How can I test whether a command's output is an empty string while not   interfering with buffering?  Example:  command | ??? if [ $? = 0 ] &amp;&amp; [ -n "$output_from_command"]; then    ...   I want the output from the code above to be the same as when running command.
102614
Today I happened to press ' after ls So the command is ls' &gt; ls' quote&gt; ls' zsh: command not found: ls\nls &gt;  Can someone tell me, what is the ls quote thing?