Last active
October 2, 2018 04:50
-
-
Save lantrix/b21aef751fad67804a5cb8dbe9290ce5 to your computer and use it in GitHub Desktop.
Processing filenames using an array - from https://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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