1

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"

2
  • What is wrong with if [[ -f $file ]] || [[ -L $file ]]? Commented Oct 17, 2014 at 11:33
  • st1=$( -f "${ARRAY[$i]}" ) doesn't make sense. The $( ... ) construct requires a command between the parentheses. -f is not a command; it's an argument to the test, [, or [[ command. You should have gotten an error like bash: -f: command not found, not expected unary operator; did you copy-and-paste your exact code? Commented Oct 17, 2014 at 18:24

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Okay but what was the problem?
I think I mentioned about intermediate variable creation. Let me add more explanation.
Please, don't wrap non-code in code formatting. :P (Answer is better now, assuming it's correct (I don't know))
It should be an OR operator instead of AND, but the rest of it helped, thank you
Oh right, it is updated now. Glad it all worked out.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.