Bash-对变量动手脚

才疏学浅,最近才注意到变量操作中的一些用法,也由此找到了一个好网站

Operations on variables

  • 1.Length of a variable(获取变量长度)
  • 2.Transformations of variables (变换变量)
  • 3.Removing substrings (删除变量中的子串)
  • 4.Replacing parts of variable names (替换变量中的一部分)

其中的第2点的写法尤其的惊艳到我,非常的简洁但有效,供上网站上的代码帮助理解一下。

1
2
3
4
5
6
7
8
9
10
11
12
~ echo ${TEST:-test}
test

~ echo $TEST

~ export TEST=a_string

~ echo ${TEST:-test}
a_string

~ echo ${TEST2:-$TEST}
a_string
Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2019-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~