OSDN Git Service

Regular updates
[twpd/master.git] / bash.md
diff --git a/bash.md b/bash.md
index a25ff35..1943cb1 100644 (file)
--- a/bash.md
+++ b/bash.md
@@ -3,7 +3,7 @@ title: Bash scripting
 category: CLI
 layout: 2017/sheet
 tags: [Featured]
-updated: 2020-07-04
+updated: 2020-07-05
 keywords:
   - Variables
   - Functions
@@ -18,6 +18,14 @@ Getting started
 ---------------
 {: .-three-column}
 
+### Introduction
+{: .-intro}
+
+This is a quick reference to getting started with Bash scripting.
+
+- [Learn bash in y minutes](https://learnxinyminutes.com/docs/bash/) _(learnxinyminutes.com)_
+- [Bash Guide](http://mywiki.wooledge.org/BashGuide) _(mywiki.wooledge.org)_
+
 ### Example
 
 ```bash
@@ -154,7 +162,7 @@ echo ${STR/foo/bar} # /path/to/bar.cpp
 ```bash
 STR="Hello world"
 echo ${STR:6:5}   # "world"
-echo ${STR:-5:5}  # "world"
+echo ${STR: -5:5}  # "world"
 ```
 
 ```bash
@@ -335,13 +343,16 @@ fi
 
 ### Arguments
 
-| Expression | Description                            |
-| ---        | ---                                    |
-| `$#`       | Number of arguments                    |
-| `$*`       | All arguments                          |
-| `$@`       | All arguments, starting from first     |
-| `$1`       | First argument                         |
-| `$_`       | Last argument of the previous command  |
+| Expression | Description                                      |
+| ---        | ---                                              |
+| `$#`       | Number of arguments                              |
+| `$*`       | All postional arguments  (as a single word)     |
+| `$@`       | All postitional arguments (as separate strings)  |
+| `$1`       | First argument                                   |
+| `$_`       | Last argument of the previous command            |
+
+**Note**: `$@` and `$*` must be quoted in order to perform as described.
+Otherwise, they do exactly the same thing (arguments as separate strings).
 
 See [Special parameters](http://wiki.bash-hackers.org/syntax/shellvars#special_parameters_and_shell_variables).
 
@@ -615,7 +626,7 @@ $((a + 200))      # Add 200 to $a
 ```
 
 ```bash
-$((RANDOM%=200))  # Random number 0..200
+$(($RANDOM%200))  # Random number 0..199
 ```
 
 ### Subshells