码迷,mamicode.com
首页 > 系统相关 > 详细

Linux Shell中的命令替换

时间:2020-05-22 09:32:17      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:int   注意   class   有用   china   lin   bash   linux   http   

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中的命令替换

标签:int   注意   class   有用   china   lin   bash   linux   http   

原文地址:https://www.cnblogs.com/99876w/p/12934959.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!