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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -