Oftentimes I run into small bash scripts that use this sort of syntax in if statements:  some command > /dev/null 2>&1  What is the purpose of outputting to /dev/null like that, and what does the 2&gt;&amp;1 mean?  It always seems to work but I'd like to know what it's doing.
68884
I would like a brief explanation of the following command line:  grep -i 'abc' content 2&gt;/dev/null
108847
If I type ' (single quote, next to the &lt;enter&gt; button) in the terminal and then press enter it drops to a &gt; prompt.  What exactly is this, what's it used for, and what type of commands can I enter here?    I can &lt;Ctrl-C&gt; out of it but that's all I got.
96219
I was playing around in a shell and typed ./. I go the following output:  bash: ./: Is a directory   It looks like "./" checks if a directory with the given name exist. I was trying to find documentation on this to see if my understanding was right, but can't find anything online. Can anyone explain this one to me?
65166
It seems like my code works to check for null if I do  if ($tx)    or   if (isset($tx))   why would I do the second one when it's harder to write?
70818
My question is on return values produced by this code:  if [ -n ]; then echo "true"; else echo "false"; fi   This prints true.  Its complementary test using [ -z ] also prints true:  if [ -z ]; then echo "true"; else  echo "false"; fi   In the above code, why does the [ -n ] test assume the string value that is not passed at all, as not null?  The code below prints false. This is expected since the passed string value is null and of zero length.  if [ -n "" ]; then echo "true"; else  echo "false"; fi
61890
I see stuff like command 1&gt; out or with 2&gt;&amp;1 to redirect stderr, but sometimes I also see &amp;&gt; by itself, etc.  What is the best way to understand &amp; and what it means exactly?
10776
I know these are few special variables used by bash. But I am not able to understand them. Can anyone explain what these variables are and how to use them?  $*  $@  $#
12613
I often see tutorials on the web or posts on this site which make heavy use of the following characters at the command line. Often it seems that they are used for pretty similar purposes. What are the differences between them when used on the command line or for shell programming? For what purpose do I use which of them?  " " double quotes  ' ' single quotes  ` ` backticks
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?
2926
How should I write the command variable to get the expected behavior?  #!/bin/bash  function f ( ) {     echo "$2" } command="f --option=\"One Two Three\" --another_option=\"Four Five Six\"" $command  f --option="One Two Three" --another_option="Four Five Six"   First calling is wrong, second - right  $&gt; ./test.sh  Two --another_option=Four Five Six
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
42698
That is literal, {fd} isn't a placeholder. I have a script that does this, and does not source in anything, nor does it reference {fd} anywhere else.  Is this valid bash?  exec {fd}&lt;/dev/watchdog
778
Usually, $0 in a script is set to the name of the script, or to whatever it was invoked as (including the path). However, if I use bash with the -c option, $0 is set to the first of the arguments passed after the command string:  bash -c 'echo $0' foo bar  # foo    In effect, it seems like positional parameters have been shifted, but including $0. However shift in the command string doesn't affect $0 (as normal):  bash -c 'echo $0; shift; echo $0' foo bar # foo # foo   Why this apparently odd behaviour for command strings? Note that I am looking for the reason, the rationale, behind implementing such odd behaviour.     One could speculate that such a command string wouldn't need the $0 parameter as usually defined, so for economy it is also used for normal arguments. However, in that case the behaviour of shift is odd. Another possibility is that $0 is used to define the behaviour of programs (a la bash called as sh or vim called as vi), but that cannot be, since $0 here is only seen in the command string and not by programs called within it. I cannot think of any other uses for $0, so I am at a loss to explain this.
23870
I've used the following script to see if a file exists:  #!/bin/bash  FILE=$1      if [ -f $FILE ]; then    echo "File $FILE exists." else    echo "File $FILE does not exist." fi   What's the correct syntax to use if I only want to check if the file does not exist?  #!/bin/bash  FILE=$1      if [ $FILE does not exist ]; then    echo "File $FILE does not exist." fi
91230
What does the following code do in C/C++?  if (blah(), 5) {     //do something }
15751
I saw the following syntax in a bash script:   &gt;$(command) &amp;   I know that the ampersand &amp; at the end makes a command run in the background, but I have never seen it in combination with the dollar sign plus the brackets around the command.  What does it do?
86602
Sometimes I see the following command:   find . -name  * -exec ls -a {} \;   I was asked to execute this.  What does {} \; mean here?