Register now and start sharing your code snippets.
-->

Check if a file or directory exists with bash

Shell Script (Bash) posted about 1 year ago by christian

This script tests if nginx exists and is executable. The script prints a warning and exits, if nginx doesn’t exists or isn’t executable:

   1  DAEMON=/usr/local/sbin/nbinx
   2  if [ ! -x $DAEMON ]
   3  then
   4     echo "Couldn't find $DAEMON. Please set path to DAEMON."
   5     exit 0
   6  fi

See man test for more information on how to use the test command.

Tagged nginx, daemon, bash, linux, debian