Skip to main content
added 46 characters in body
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242

others have noted the { compound command ;} grouping, but if you are performing identical tests on a set you might like to use a different kind:

if  ! for f in file1 file2 file3
      do  [ -f "$f" ] || ! break
      done
then  : do stuff
fi

...as is elsewhere demonstrated with { :;}, there is no difficulty involved with nesting compound commands...

Note that the above (typically) tests for regular files. If you're looking only for existing, accessiblereadable files which are not directories:

if  ! for f in file1 file2 file3
      do  [ ! -d "$f" ] && 
          [   -er "$f" ] || ! break
      done
then  : do stuff
fi

If you don't care whether they are directories or not:

if  ! command <file1 <file2 <file3
then  : do stuff
fi

...works for any readable, accessible file, but will likely hang for fifos w/out writers.

others have noted the { compound command ;} grouping, but if you are performing identical tests on a set you might like to use a different kind:

if  ! for f in file1 file2 file3
      do  [ -f "$f" ] || ! break
      done
then  : do stuff
fi

...as is elsewhere demonstrated with { :;}, there is no difficulty involved with nesting compound commands...

Note that the above (typically) tests for regular files. If you're looking only for existing, accessible files which are not directories:

if  ! for f in file1 file2 file3
      do  [ ! -d "$f" ] && [ -e "$f" ] || ! break
      done
then  : do stuff
fi

If you don't care whether they are directories or not:

if  ! command <file1 <file2 <file3
then  : do stuff
fi

...works for any readable, accessible file.

others have noted the { compound command ;} grouping, but if you are performing identical tests on a set you might like to use a different kind:

if  ! for f in file1 file2 file3
      do  [ -f "$f" ] || ! break
      done
then  : do stuff
fi

...as is elsewhere demonstrated with { :;}, there is no difficulty involved with nesting compound commands...

Note that the above (typically) tests for regular files. If you're looking only for existing, readable files which are not directories:

if  ! for f in file1 file2 file3
      do  [ ! -d "$f" ] && 
          [   -r "$f" ] || ! break
      done
then  : do stuff
fi

If you don't care whether they are directories or not:

if  ! command <file1 <file2 <file3
then  : do stuff
fi

...works for any readable, accessible file, but will likely hang for fifos w/out writers.

Rollback to Revision 2
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242

others have noted the { compound command ;} grouping, but if you are performing identical tests on a set you might like to use a different kind:

if  ! for f in file1 file2 file3
      do  [ -f "$f" ] || ! break
      done
then  : do stuff
fi

...as is elsewhere demonstrated with { :;}, there is no difficulty involved with nesting compound commands...

Note that the above (typically) tests for regular files. If you're looking only for readableexisting, accessible files which are not directories:

if  ! for f in file1 file2 file3
      do    [ ! -d "$f" ] <"$f"&& [ -e "$f" ] || ! break
      done
then  2>/dev/null: do stuff
fi

If you don't care whether they are directories or not:

if  ! command <file1 <file2 <file3
then  : do stuff
fi

...works for any readable, accessible file.

others have noted the { compound command ;} grouping, but if you are performing identical tests on a set you might like to use a different kind:

if  ! for f in file1 file2 file3
      do  [ -f "$f" ] || ! break
      done
then  : do stuff
fi

...as is elsewhere demonstrated with { :;}, there is no difficulty involved with nesting compound commands...

Note that the above (typically) tests for regular files. If you're looking only for readable, accessible files which are not directories:

if  ! for f in file1 file2 file3
      do    [ ! -d "$f" ] <"$f" || ! break
      done  2>/dev/null
then  : do stuff
fi

others have noted the { compound command ;} grouping, but if you are performing identical tests on a set you might like to use a different kind:

if  ! for f in file1 file2 file3
      do  [ -f "$f" ] || ! break
      done
then  : do stuff
fi

...as is elsewhere demonstrated with { :;}, there is no difficulty involved with nesting compound commands...

Note that the above (typically) tests for regular files. If you're looking only for existing, accessible files which are not directories:

if  ! for f in file1 file2 file3
      do  [ ! -d "$f" ] && [ -e "$f" ] || ! break
      done
then  : do stuff
fi

If you don't care whether they are directories or not:

if  ! command <file1 <file2 <file3
then  : do stuff
fi

...works for any readable, accessible file.

deleted 174 characters in body
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242

others have noted the { compound command ;} grouping, but if you are performing identical tests on a set you might like to use a different kind:

if  ! for f in file1 file2 file3
      do  [ -f "$f" ] || ! break
      done
then  : do stuff
fi

...as is elsewhere demonstrated with { :;}, there is no difficulty involved with nesting compound commands...

Note that the above (typically) tests for regular files. If you're looking only for existingreadable, accessible files which are not directories:

if  ! for f in file1 file2 file3
      do    [ ! -d "$f" ] && [ -e "$f" ]<"$f" || ! break
      done
then  : do stuff
fi

If you don't care whether they are directories or not:

if  ! command <file1 <file2 <file32>/dev/null
then  : do stuff
fi

...works for any readable, accessible file.

others have noted the { compound command ;} grouping, but if you are performing identical tests on a set you might like to use a different kind:

if  ! for f in file1 file2 file3
      do  [ -f "$f" ] || ! break
      done
then  : do stuff
fi

...as is elsewhere demonstrated with { :;}, there is no difficulty involved with nesting compound commands...

Note that the above (typically) tests for regular files. If you're looking only for existing, accessible files which are not directories:

if  ! for f in file1 file2 file3
      do  [ ! -d "$f" ] && [ -e "$f" ] || ! break
      done
then  : do stuff
fi

If you don't care whether they are directories or not:

if  ! command <file1 <file2 <file3
then  : do stuff
fi

...works for any readable, accessible file.

others have noted the { compound command ;} grouping, but if you are performing identical tests on a set you might like to use a different kind:

if  ! for f in file1 file2 file3
      do  [ -f "$f" ] || ! break
      done
then  : do stuff
fi

...as is elsewhere demonstrated with { :;}, there is no difficulty involved with nesting compound commands...

Note that the above (typically) tests for regular files. If you're looking only for readable, accessible files which are not directories:

if  ! for f in file1 file2 file3
      do    [ ! -d "$f" ] <"$f" || ! break
      done  2>/dev/null
then  : do stuff
fi
edited body
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242
Loading
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242
Loading