bash - Loop through files within a path (with spaces) -


i wanted pass path name script, path has spaces (eg. /users/netto/itunes \media/music/). have tried putting actual path directly on loop, , able files. unfortunately, not pass variable. have tried both double quote, , single quote. have currently

$path=$1 f in $path;    echo "processing file $f "  done 

please let me know on how this. thank in advance.

spaces in variables expanded @ command level, solve problem can either put quotation marks around "$1" (so spaces escaped) or use bash arrays.

here 2 example should work:

 #!/bin/bash dir="$1" f in "$dir"/*    echo "processing file $f "  done 

or using bash arrays:

#!/bin/bash files=("$1"*) f in "${files[@]}"   echo "processing file $f "  done 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -