mirror of
https://github.com/xmengnet/the-art-of-command-line.git
synced 2024-12-24 03:46:29 +08:00
Added curly-braces-in-script hint
Signed-off-by: Andreas Hofmann <mail@andreas-hofmann.org>
This commit is contained in:
parent
49918189ad
commit
a2d687b2fc
1 changed files with 8 additions and 0 deletions
|
@ -145,6 +145,14 @@ Notes:
|
|||
diff /etc/hosts <(ssh somehost cat /etc/hosts)
|
||||
```
|
||||
|
||||
- When writing scripts you may want to put all of your code in curly braces:
|
||||
```sh
|
||||
{
|
||||
# Your code here
|
||||
}
|
||||
```
|
||||
If the closing brace is missing, your script will be prevented from executing due to a syntax error. This makes sense when your script is going to be downloaded from the web, since it prevents partially downloaded scripts from executing.
|
||||
|
||||
- Know about "here documents" in Bash, as in `cat <<EOF ...`.
|
||||
|
||||
- In Bash, redirect both standard output and standard error via: `some-command >logfile 2>&1` or `some-command &>logfile`. Often, to ensure a command does not leave an open file handle to standard input, tying it to the terminal you are in, it is also good practice to add `</dev/null`.
|
||||
|
|
Loading…
Reference in a new issue