bash 如何将tail -1输入到sh脚本var中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11042514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 02:30:08  来源:igfitidea点击:

How to input tail -1 into sh script var

linuxbashshell

提问by Rhys

AIM: I would like to tail the last line of the file.txt and input into a variable to use for substitution via sed.

目的:我想拖尾 file.txt 的最后一行并输入到一个变量中以用于通过 sed 进行替换。

CODE:

代码:

 ALARM_POPUP_CONTENT=(tail -1 /logs/file.txt)
 ALARM_POPUP_CONTENT=tail -1 /logs/file.txt

OUTCOME:

结果:

This is only outputtin the work 'tail' or an error command not found for the seond option. Any suggestions?

这只是输出工作'tail'或找不到第二个选项的错误命令。有什么建议?

回答by jedwards

Try:

尝试:

ALARM_POPUP_CONTENT=$(tail -1 /logs/file.txt)

or with backticks:

或带反引号:

ALARM_POPUP_CONTENT=`tail -1 /logs/file.txt`