I have been trying to find online what these if statement mean. Below are a few.

if [ "${snums[k]}" != "NA" -a ! -f "${aliases[k]}.4dfp.img" ]; then
if [ -f "$dcmfile" -a -n "`cat $dcmfile`" ]; then

The -a used in these two examples do not make senses to me.

  • A good reason you may not have seen -a or -o is that they have been declared "obsolescent" by POSIX. Script authors are strongly encouraged to use the shell's && and || instead – Fox Jul 10 '18 at 23:20
  • Oh i see. I always thought -a was for checking to see if a file exists. – Aaron Tanenbaum Jul 11 '18 at 15:41

-a is logical AND. If both the operands are true, then the condition becomes true otherwise false.

-n Checks if the given string operand size is non-zero; if it is nonzero length, then it returns true.

  • 1
    And -f checks if the following word is a regular file. Also, you can use -s to check if a file is not empty. – l0b0 Jul 10 '18 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.