Skip to content

Instantly share code, notes, and snippets.

@ijoseph
Created March 6, 2017 04:32
Show Gist options
  • Save ijoseph/f3a7bfc5e8910a535da52df78e29fd69 to your computer and use it in GitHub Desktop.
Save ijoseph/f3a7bfc5e8910a535da52df78e29fd69 to your computer and use it in GitHub Desktop.
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