So im trying to rename all files in a directory, so that they do not have spaces. Im doing a bash script and im really not sure what to do, i've tried all kinds of quotes and escaping but im not sure what combo could work.
#!/bin/bash #change empty spaces in filenames to underlineos lsarray="$(echo "$(pwd)""/*")" for i in $lsarray do if [[ $i == *" "* ]] then line=$(echo $i | sed 's/ \+/\_/g') j=$(echo $i | sed 's/ \+/\\ /g') mv "$j" "$line" echo "$i" echo "$j" echo "$line" fi done
since mv needs "special variable expansion" im using double quotes on it. Any tips appreciated.