dirs=$(find . -type d 2>/dev/null | cut -c 3-)
# needed for zsh
setopt sh_word_split
SAVEIFS=$IFS # Save current IFS
IFS=$'\n' # Change IFS to new line
dirs=($dirs) # split to array
IFS=$SAVEIFS # Restore IFS
for dir in $dirs; do
originalDir=$(pwd)
cd $dir
COMMAND ##### REPLACE THIS
cd $originalDir
done
Replace COMMAND with your command
dirs=$(find . -type d 2>/dev/null | cut -c 3-)
# needed for zsh
setopt sh_word_split
SAVEIFS=$IFS # Save current IFS
IFS=$'\n' # Change IFS to new line
dirs=($dirs) # split to array
IFS=$SAVEIFS # Restore IFS
for dir in $dirs; do
originalDir=$(pwd)
cd $dir
pwd ### REPLACE THIS
cd $originalDir
done
dirs=$(find . -maxdepth 1 -type d 2>/dev/null | cut -c 3-)
# needed for zsh
setopt sh_word_split
SAVEIFS=$IFS # Save current IFS
IFS=$'\n' # Change IFS to new line
dirs=($dirs) # split to array
IFS=$SAVEIFS # Restore IFS
for dir in $dirs; do
originalDir=$(pwd)
cd $dir
COMMAND #### REPLACE THIS
cd $originalDir
done
if test -f "FILE"; then
YOURCOMMAND
fi
Example:
if test -f "package.json"; then
echo $FILE
fi
find . -type d | cut -c 3-
find . -maxdepth 1 -type d | cut -c 3-
find . -maxdepth 1 -type d -print 2>/dev/null | cut -c 3-
items="Item 1
Item 2
Item 3"
# needed for zsh
setopt sh_word_split
SAVEIFS=$IFS # Save current IFS
IFS=$'\n' # Change IFS to new line
items=($items) # split to array
IFS=$SAVEIFS # Restore IFS
for item in $items; do
COMMAND #### REPLACE THIS
done
Example
items="Item 1
Item 2
Item 3"
# needed for zsh
setopt sh_word_split
SAVEIFS=$IFS # Save current IFS
IFS=$'\n' # Change IFS to new line
items=($items) # split to array
IFS=$SAVEIFS # Restore IFS
for item in $items; do
echo $item #### REPLACE THIS
done
function FUNCTIONNAME { #### REPLACE FUNCTIONNAME with your function name
while test $# -gt 0; do # For each argument
case "$1" in
-h|--help)
echo "-h, --help show brief help"
echo "-f boolean flag command -f"
echo "--action ACTION flag with value"
exit 0
;;
-f)
shift
FLAG=true #### CHANGE THIS
;;
--action*) #### CHANGE THIS
shift
ACTION=`echo $1 | sed -e 's/^[^=]*=//g'`
;;
*)
shift
ARGS=`echo $1`
break
;;
esac
done
[[ FLAG ]] && echo "Flagged"
[[ ACTION ]] && echo "ACTION: $ACTION"
[[ ARGS ]] && echo $ARGS
}
FUNCTIONNAME -f --action testing word