[英]Taking input in bash from the output on terminal
以下是从我的终端复制的:
home:Doc$ grep AAA: testfile.txt
1 5 5 9 90 8.0 -7.0 1.5 500 b, AAA: ( 9 9 5)
在 bash 脚本中,我想包含 grep 命令,如上所示。 然后我想将 output 中的“500”分配给变量“var1”。 有没有办法做到这一点? 所以我的 bash 脚本看起来像:
#!/bin/bash
grep AAA: testfile.txt
# I want to assign var1 = 500
或者有没有办法直接从文件“testfile.txt”中获取输入?
请给我一些想法。 提前致谢。
x="1 5 5 9 90 8.0 -7.0 1.5 500 b, AAA: ( 9 9 5)"
y=$(echo $x | cut -d " " -f 9)
会做的。 测试
y=$(echo $x | cut -d " " -f 9) && echo $y //500
所以在你的上下文中 let x=$(grep AAA: testfile.txt)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.