我有几个脚本我正在使用Bash shell的所有权,在条件语句中有一个find语句。来自条件语句的变量
事情是这样的:
if [ -z $(find/-type f -perm -002) ] ; then echo "no world writable found"
那里作为否则我想显示什么被发现的,而不是world write perms found
。
我可以这样做:
echo $(find/-type f -perm -002) has world write permissions
或变量设置为$(find/-type f -perm -002)
。
但想知道是否有更好的方法来做到这一点。是否有另一种方法来检索find语句的内容作为变量?
将查找结果赋给变量有什么不对? – ceving 2014-10-17 12:40:57
'result = $(find/-type f -perm -002)'或'local result = $(find/-type f -perm -002)'如果包含在函数中将是惯用的方式。 – helpermethod 2014-10-17 12:47:37
请注意,在原文中,您需要引用命令替换,因为如果它扩展为多个单词,'['会抱怨太多的操作数。 – chepner 2014-10-17 12:54:33