Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # https://stackoverflow.com/questions/34077070/what-does-e-and-ne-means-in-bash-script
- # just in case bash isn't available, this runs fine with sh
- #user variables should always be lowercase
- expected_args=1
- e_badargs=1
- #it's good practice to quote all variables, even if you know they're numbers
- if [ "$#" -ne "$expected_args" ]; then
- echo "Usage: $(basename $0) {arg}"
- exit "$e_badargs"
- fi
- #check if this is a directory, not just that it exists
- if [ ! -d "$1" ]; then
- echo "$1 does not exist or is not a directory"
- exit "$e_badargs"
- fi
- #quote this, in case there's a space in the directory name
- for myfile in "$1"/*; do
- #also quote $myfile in case of spaces in the file name
- if [ -d "$myfile" ]; then
- echo "$myfile (DIR)"
- elif [ -f "$myfile" ]; then
- echo "$myfile"
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement