Skip to content

Instantly share code, notes, and snippets.

@tanzyy
Last active April 13, 2017 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanzyy/4db3af0e00e7903456ef29768a2529eb to your computer and use it in GitHub Desktop.
Save tanzyy/4db3af0e00e7903456ef29768a2529eb to your computer and use it in GitHub Desktop.
#!/bin/bash
# This method finds last name separated by /, helps in getting directory or file name without path.
print_name() {
echo $1 | awk -F "/" '{ print $NF }'
}
dir_name=/Users/tanzyy/_temp/logshomedir/*
for d in $dir_name; do
if [ -d "$d" ]; then
# Here you can find example of how to call method in echo method
echo "Its dir - " $(print_name $d)
for f in $d/*; do
echo "The file is " $(print_name $f)
done
else
echo "Its file - " $(print_name $d)
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment