2
如何将命令的输出分配给shell变量?
我想将表达式的结果分配给变量并将其与字符串连接,然后回显它。这是我得到的: #!/bin/bash cd ~/Desktop; thefile= ls -t -U | grep -m 1 "Screen Shot"; echo "Most recent screenshot is: "$thefile; 但是输出: Screen Shot 2011-07-03 at 1.55.43 PM.png Most recent screenshot is: 因此,它似乎没有分配给$thefile,而是在执行时被打印。