导航

shell变量

  • 变量赋值

first=issac middle=bashevis

shell变量赋值等号左右无空格

oldname=$fullname

oldname="$fullname"

取变量值时,变量前加$,可以不加引号,也可以加引号

fullname="issac bashevis"

值包含空格,需要用引号括起来

fullname="$first $middle"

将若干个变量连接起来,需要使用引号

删除变量

unset fullname

  • 反引号

将shell命令用反引号括起来,shell命令的输出即可作为参数。

kill -9 `pidof ssh`

# <----->

ps -ef | grep ssh
kill -9 xxx
  •  local字段

修饰变量。在函数中定义,该变量作用域局限于函数内部。

posted on 2021-04-07 11:58  toughcactus  阅读(44)  评论(0编辑  收藏  举报