125 # Returns a shell-escaped version of the argument given. |
125 # Returns a shell-escaped version of the argument given. |
126 function shell_quote() { |
126 function shell_quote() { |
127 if [[ -n "$1" ]]; then |
127 if [[ -n "$1" ]]; then |
128 # Uses only shell-safe characters? No quoting needed. |
128 # Uses only shell-safe characters? No quoting needed. |
129 # '=' is a zsh meta-character, but only in word-initial position. |
129 # '=' is a zsh meta-character, but only in word-initial position. |
130 if [[ "$1" =~ ^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.:,%/+=_-]+$ && ! "$1" =~ ^= ]]; then |
130 if echo "$1" | grep -qE '^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.:,%/+=_-]+$' \ |
|
131 && ! echo "$1" | grep -qE '^='; then |
131 quoted="$1" |
132 quoted="$1" |
132 else |
133 else |
133 if [[ "$1" =~ [\'!] ]]; then |
134 if echo "$1" | grep -qE "[\'!]"; then |
134 # csh does history expansion within single quotes, but not |
135 # csh does history expansion within single quotes, but not |
135 # when backslash-escaped! |
136 # when backslash-escaped! |
136 local quoted_quote="'\\''" quoted_exclam="'\\!'" |
137 local quoted_quote="'\\''" quoted_exclam="'\\!'" |
137 word="${1//\'/${quoted_quote}}" |
138 word="${1//\'/${quoted_quote}}" |
138 word="${1//\!/${quoted_exclam}}" |
139 word="${1//\!/${quoted_exclam}}" |