Skip to content

Instantly share code, notes, and snippets.

@wdzajicek
Created July 24, 2018 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wdzajicek/150ead3f48be74d8c89b3b3a431cd093 to your computer and use it in GitHub Desktop.
Save wdzajicek/150ead3f48be74d8c89b3b3a431cd093 to your computer and use it in GitHub Desktop.
Have Terminal Echo Characters That Must Be Escaped
#!/bin/bash
# Save this code as 'bashreg.sh' and run it in terminal `$ sh bashreg.sh`
special=$'`!@#$%^&*()-_+={}|[]\\;\':",.<>?/ '
for ((i=0; i < ${#special}; i++)); do
char="${special:i:1}"
printf -v q_char '%q' "$char"
if [[ "$char" != "$q_char" ]]; then
printf 'Yes - character %s needs to be escaped\n' "$char"
else
printf 'No - character %s does not need to be escaped\n' "$char"
fi
done | sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment