Advertisement
miken32

What does -e and -ne means in bash script?

Dec 3rd, 2015 (edited)
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.82 KB | None | 0 0
  1. #!/bin/sh
  2. # https://stackoverflow.com/questions/34077070/what-does-e-and-ne-means-in-bash-script
  3. # just in case bash isn't available, this runs fine with sh
  4.  
  5. #user variables should always be lowercase
  6. expected_args=1
  7. e_badargs=1
  8.  
  9. #it's good practice to quote all variables, even if you know they're numbers
  10. if [ "$#" -ne "$expected_args" ]; then
  11.   echo "Usage: $(basename $0) {arg}"
  12.   exit "$e_badargs"
  13. fi
  14.  
  15. #check if this is a directory, not just that it exists
  16. if [ ! -d "$1" ]; then
  17.   echo "$1 does not exist or is not a directory"
  18.   exit "$e_badargs"
  19. fi
  20.  
  21. #quote this, in case there's a space in the directory name
  22. for myfile in "$1"/*; do
  23.   #also quote $myfile in case of spaces in the file name
  24.   if [ -d "$myfile" ]; then
  25.     echo "$myfile (DIR)"
  26.   elif [ -f "$myfile" ]; then
  27.     echo "$myfile"
  28.   fi
  29. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement