Shell scripts usually have the first sentence #!/bin/bash. In many cases, if this line is not set, the program is likely to be unable to execute because the system cannot determine what shell the program needs to use to execute.
In simple terms, #!/bin/bash: refers to the use of /bin/bash to explain the execution of this script. Among them, #! is a special indicator followed by the shell path to explain the script. bash is just a type of shell, and there are many other shells, such as: sh, csh, ksh, tcsh, etc.
There are three types of quotes in Linux Shell, namely double quotes (" "), single quotes (' ') and backticks (` `).
The double quotes replace $, '', ` and \ that appear in the string; the single quotes are not replaced, and all characters in the string are output as normal characters, while the string in the backquotes is executed as shell commands, and the execution result is returned. The specific meanings are as follows:
Double quotes (" "): In double quotes, all characters except $, '', ` and \ are interpreted as the characters themselves.
Single quotes (' '): All characters in single quotes, including special characters ($,'', ` and \) will be interpreted as characters themselves and become ordinary characters.
Backticks (``): The string in the backticks will be interpreted as a shell command to execute.
Backticks are the old usage, $() is the new usage, and it is recommended to use $(). The usage method is consistent with the backticks, as follows:
DATE1=`date` DATE2=$(date)
Usually, the two forms of variable substitution are equivalent, but there is a little difference between the two. Backticks `` does not support nesting, while $() supports nesting, such as calculating the number of lines of the first file in the directory:
lines=$(wc -l $(ls | sed -n '1p')) echo $lines
The output result is:
89
Additionally, $() is only valid in Bash Shell, while backticks are available in a variety of shells.
This article about the role of /bin/bash in shell scripts, and the use of quotes and brackets is introduced here. For more related shell contents, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!