Skip to content

Instantly share code, notes, and snippets.

@RobertKielty
Created July 16, 2015 12:58
Show Gist options
  • Save RobertKielty/4ec37ee80b4e32bf9fff to your computer and use it in GitHub Desktop.
Save RobertKielty/4ec37ee80b4e32bf9fff to your computer and use it in GitHub Desktop.
#!/bin/bash
# Iterate over dirs in a directory
# ref http://www.tldp.org/LDP/abs/html/parameter-substitution.html for param subs
TEST_DIR="/tmp/"
for dir in $TEST_DIR*/ ; do
echo "Full path : " ${dir}
dir=${dir%*/} # remove trailing slash
echo "Path minus trailing /" ${dir}
echo "Bare directory name" ${dir##*/} # remove everything up to the remaining lash
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment