简体   繁体   中英

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. 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:

-f: command not found

since shell will consider f as a command name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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