小编Nat*_* G.的帖子

如何将命令的输出分配给 shell 变量?

我想将表达式的结果(即命令的输出)分配给一个变量,然后对其进行操作——例如,将它与一个字符串连接起来,然后回显它。这是我所拥有的:

#!/bin/bash
cd ~/Desktop;
thefile= ls -t -U | grep -m 1 "Screen Shot";
echo "Most recent screenshot is: "$thefile;
Run Code Online (Sandbox Code Playgroud)

但是输出:

Screen Shot 2011-07-03 at 1.55.43 PM.png
Most recent screenshot is: 
Run Code Online (Sandbox Code Playgroud)

因此,它看起来没有分配给$thefile,并且在执行时正在打印。

我错过了什么?

bash io-redirection shell-script variable

95
推荐指数
3
解决办法
32万
查看次数

标签 统计

bash ×1

io-redirection ×1

shell-script ×1

variable ×1