Convert Filename to Bash-Friendly Filename (with Dashes)
This file contains 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
#dash escape filename (version 0.1: must be in current working dir) | |
dashef(){ | |
filename=`basename $1 | tr "\n" " "` | |
# echo "filename is ${filename}" | |
escaped=`echo $1 | tr " " "-" |tr -d "," | tr "_" "-" | tr "(" "-" | tr ")" "-" | tr "+" "-" | perl -pe 's/\-\-\-/\-/g' | perl -pe 's/\-\-/\-/g'` | |
echo "filename is now $escaped" | |
mv "${1}" ${escaped} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To escape every filename in the current directory:
for f in *; do dashef "${f}"; done