file_check.sh (767B)
1 #!/usr/bin/env bash 2 # File : file_check.sh 3 # Description: Test type of file passed as argument to the script 4 # Copyright 2022 Harvard University. All Rights Reserved. 5 6 if [ $# -ne 1 ]; then 7 cat <<EOF 8 USAGE: $0 <path/to/file> 9 10 More documentation here. The form used here is called a here-document. 11 They are very useful to write longer strings and expanding variables like 12 \$0 above. See https://tldp.org/LDP/abs/html/here-docs.html 13 EOF 14 exit 1 # exit with failure code 15 fi 16 17 if [ -f $1 ]; then 18 echo "File $1 exists and is a regular file" 19 elif [ -d $1 ]; then 20 echo "File $1 exists and is a directory" 21 elif [ -e $1 ]; then 22 # any other file type (character, block or symbolic link) 23 echo "File $1 exists and is an unknown file" 24 fi