Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
leondgarse committed Feb 23, 2024
1 parent 2b49b6c commit 47454a2
Show file tree
Hide file tree
Showing 4 changed files with 496 additions and 349 deletions.
14 changes: 14 additions & 0 deletions public/2017/01-04_Shell_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@
echo ${my_array[3]} # 需要使用{} --> orange
```
- 数组拼接
```sh
aa=("aa" "bb" "cc")
aa=(${aa[@]} "dd")
echo ${aa[@]}
# aa bb cc dd
```
- ($(EXP)) 初始化为命令输出的数组
```shell
FILELIST=($(ls))
Expand All @@ -121,6 +128,7 @@
- ${#VAR[@]} ${#VAR[\*]} 元素数目
```shell
echo ${#my_array[@]} # 输出元素数目 --> 4
echo ${#my_array[@]} # 输出元素数目 --> 4
# adding another array element
my_array[4]="carrot" # value assignment without a $ and curly brackets
Expand Down Expand Up @@ -391,6 +399,12 @@
if [[ ! $FF =~ ^[0-9] ]]; then echo "string"; else echo "number"; fi
# number
```
用于判断包含子串
```sh
AA="hello world"
if [[ $AA =~ "wor" ]]; then echo $AA; fi
# hello world
```
- **`if [ -n $STR ]`**`$STR` 为空时会返回 `True`
```sh
aa=""
Expand Down
Loading

0 comments on commit 47454a2

Please sign in to comment.