Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert Filename to Bash-Friendly Filename (with Dashes)
#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}
}
@ijoseph
Copy link
Author

ijoseph commented Mar 6, 2017

To escape every filename in the current directory: for f in *; do dashef "${f}"; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment