简体   繁体   English

bash如果语句期望一元运算符

[英]bash if statement expected unary operator

I'm trying to do something along lines of 我正在尝试做一些类似的事情

if (!regular file || symbolic link)
    continue

What I have so far is 我到目前为止所拥有的是

st1=$( -f "${ARRAY[$i]}" )                                                 
 if [ "$st1" -eq 0 ] 

but I'm getting "expected unary operator error" 但我收到“预期的一元运算符错误”

You don't need to create intermediate st1 variable. 您不需要创建中间的st1变量。 Just use: 只需使用:

if [[ ! -f "${ARRAY[$i]}" || -h "${ARRAY[$i]}" ]]; then
    echo "${ARRAY[$i]} link exists"
fi

Your use of st1=$( -f "${ARRAY[$i]}" ) is incorrect and will cause syntax error: 您对st1=$( -f "${ARRAY[$i]}" )的使用不正确,将导致语法错误:

-f: command not found

since shell will consider f as a command name. 因为shell会将f视为命令名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM