ksh将命令的结果存储到变量 [英] ksh storing result of a command to a variable
本文介绍了ksh将命令的结果存储到变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将命令的结果存储在我的shell脚本中的变量。我似乎无法得到它的工作。我想要目录中最近日期的文件。
PRODUCT ='ls -t / some / dir / file * |头-1 | xargs -n1 basename'
它不工作
$ 或反面标签
`
。 1) x = $(ls -t / some / dir / file * | head -1 | xargs -n1 basename)
或
2) x =`ls -t /一些/ dir /文件* |头-1 | xargs -n1 basename`
echo $ x
编辑:删除(2)的不必要的括号。
I want to store the result of a command to a variable in my shell script. I cant seem to get it to work. I want the most recently dated file in the directory.
PRODUCT= 'ls -t /some/dir/file* | head -1 | xargs -n1 basename'
it wont work
解决方案you have two options, either
$
or backsticks`
.1)
x=$(ls -t /some/dir/file* | head -1 | xargs -n1 basename)
or
2)
x=`ls -t /some/dir/file* | head -1 | xargs -n1 basename`
echo $x
Edit: removing unnecessary bracket for (2).
这篇关于ksh将命令的结果存储到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文