Skip to content

Instantly share code, notes, and snippets.

@lantrix
Last active October 2, 2018 04:50
Show Gist options
  • Select an option

  • Save lantrix/b21aef751fad67804a5cb8dbe9290ce5 to your computer and use it in GitHub Desktop.

Select an option

Save lantrix/b21aef751fad67804a5cb8dbe9290ce5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Processing filenames using an array - from https://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
DIR="$1"
# failsafe - fall back to current directory
[ "$DIR" == "" ] && DIR="."
# save and change IFS
OLDIFS=$IFS
IFS=$'\n'
# read all file name into an array
fileArray=($(find $DIR -type f))
# restore it
IFS=$OLDIFS
# get length of an array
tLen=${#fileArray[@]}
# use for loop read all filenames
for (( i=0; i<${tLen}; i++ ));
do
echo "${fileArray[$i]}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment