我正在寻找以下命令(或做法):
echo -n 6 | doif -criteria "isgreaterthan 4" -command 'do some stuff'
echo部分显然来自更复杂的bash命令串。基本上我从文件的每一行获取一段文本,如果它出现在多于x的另一组文件(比如100)中,那么它将被附加到另一个文件。
有没有办法用awk以某种方式执行这样的欺骗?或者是否有另一个命令..我希望有一些xargs样式命令来执行此操作,因为-I%部分将是用于检查标准的值,以及随后的任何内容将是命令执行。
感谢您的见解。
答案 0 :(得分:1)
虽然我没有看到你为什么这样做的原因,但这是可能的......
function doif
{
read val1
op=$1
val2="$2"
shift 2
if [ $val1 $op "$val2" ]; then
"$@"
fi
}
echo -n 6 | doif -gt 3 ls /
答案 1 :(得分:0)
if test 6 -gt 4; then # do some stuff fi
或
if test $( echo 6 ) -gt 4; then : ;fi
或
output=$( some cmds that generate text) # this will be an error if $output is ill-formed if test "$output" -gt 4; then : ; fi