Linux Shell中的命令替换

Posted 99876w

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux Shell中的命令替换相关的知识,希望对你有一定的参考价值。

Shell脚本中最有用的特性之1就是可以从命令输出中提取信息,并将其赋给变量。有两种方法可以将命令输出赋值给变量。

  • 反引号字符(`)

反引号字符位于键盘上ESC键的下面。赋值给变量的情势以下:

test=`date`

# demo
$ test=`date`
$ echo $test
2017年 1月11日 星期3 21时26分04秒 CST

两个反引号字符之间是shell命令,shell命令的履行结果赋值给test,注意=两边不能有空格。

  • $()情势

赋值给变量的情势以下:

test=$(date)

# demo
$ test=$(date)
$ echo $test
2017年 1月11日 星期3 21时26分35秒 CST

http://www.abc100.com/kindeditor/attached/file/20200522/20200522065527_9228.html
http://www.abc100.com/kindeditor/attached/file/20200522/20200522065644_2031.html
http://www.abc100.com/kindeditor/attached/file/20200522/20200522065758_1952.html
http://www.abc100.com/kindeditor/attached/file/20200522/20200522065608_5761.html
http://www.abc100.com/kindeditor/attached/file/20200522/20200522070024_5126.html
http://www.abc100.com/kindeditor/attached/file/20200522/20200522065721_6757.html
http://www.abc100.com/kindeditor/attached/file/20200522/20200522065833_7050.html
http://www.abc100.com/kindeditor/attached/file/20200522/20200522065520_7910.html
http://www.abc100.com/kindeditor/attached/file/20200522/20200522070018_4199.html
http://www.abc100.com/kindeditor/attached/file/20200522/20200522070011_2001.html
http://www.cere.cc/editor/attached/file/20200522/20200522065718_2698.html
http://www.cere.cc/editor/attached/file/20200522/20200522065524_4573.html
http://www.cere.cc/editor/attached/file/20200522/20200522065830_3323.html
http://www.cere.cc/editor/attached/file/20200522/20200522065516_8792.html
http://www.cere.cc/editor/attached/file/20200522/20200522065641_6917.html
http://www.cere.cc/editor/attached/file/20200522/20200522070015_8948.html
http://www.cere.cc/editor/attached/file/20200522/20200522065754_8011.html
http://www.cere.cc/editor/attached/file/20200522/20200522070008_6605.html
http://www.cere.cc/editor/attached/file/20200522/20200522065605_1917.html
http://www.cere.cc/editor/attached/file/20200522/20200522070022_0042.html
http://www.chenxi120.com/uploadfile/file/20200522/20200522070011541154.html
http://www.chenxi120.com/uploadfile/file/20200522/20200522065576737673.html
http://www.chenxi120.com/uploadfile/file/20200522/20200522065663926392.html
http://www.chenxi120.com/uploadfile/file/20200522/20200522070037553755.html
http://www.chenxi120.com/uploadfile/file/20200522/20200522065769466946.html
http://www.chenxi120.com/uploadfile/file/20200522/20200522065761986198.html
http://www.chenxi120.com/uploadfile/file/20200522/20200522070045404540.html
http://www.chenxi120.com/uploadfile/file/20200522/20200522065685148514.html
http://www.chenxi120.com/uploadfile/file/20200522/20200522070014661466.html
http://www.chenxi120.com/uploadfile/file/20200522/20200522065560976097.html
http://www.chinagreenland.com/kindeditor/attached/file/20200522/20200522065629_5633.html
http://www.chinagreenland.com/kindeditor/attached/file/20200522/20200522070041_5661.html
http://www.chinagreenland.com/kindeditor/attached/file/20200522/20200522070006_0931.html
http://www.chinagreenland.com/kindeditor/attached/file/20200522/20200522070020_0331.html
http://www.chinagreenland.com/kindeditor/attached/file/20200522/20200522070013_7360.html
http://www.chinagreenland.com/kindeditor/attached/file/20200522/20200522065819_1163.html
http://www.chinagreenland.com/kindeditor/attached/file/20200522/20200522065522_1955.html
http://www.chinagreenland.com/kindeditor/attached/file/20200522/20200522065743_6042.html
http://www.chinagreenland.com/kindeditor/attached/file/20200522/20200522065706_0666.html
http://www.chinagreenland.com/kindeditor/attached/file/20200522/20200522065551_9300.html

以上是关于Linux Shell中的命令替换的主要内容,如果未能解决你的问题,请参考以下文章

unix下KSH中shell的SED命令怎样把文件中的NULL替换成空格。 (十六进制码00替换成20)

shell :linux sed 批量替换字符串

Linux Shell 常用命令

如何在shell脚本中修改添加替换指定文件中的内容

Linux Shell 中的反引号,单引号,双引号

linux shell sed命令的问题!