... | ... |
@@ -77,3 +77,32 @@ DATE_START_ALL=$(date +%s) |
77 | 77 |
log "############################################################" |
78 | 78 |
log "Started @ $DATE_START_ALL" |
79 | 79 |
``` |
80 |
+ |
|
81 |
+# URLencode |
|
82 |
+```bash |
|
83 |
+rawurlencode() { |
|
84 |
+ local string="${1}" |
|
85 |
+ local strlen=${#string} |
|
86 |
+ local encoded="" |
|
87 |
+ local pos c o |
|
88 |
+ |
|
89 |
+ for (( pos=0 ; pos<strlen ; pos++ )); do |
|
90 |
+ c=${string:$pos:1} |
|
91 |
+ case "$c" in |
|
92 |
+ [-_.~a-zA-Z0-9] ) o="${c}" ;; |
|
93 |
+ * ) printf -v o '%%%02x' "'$c" |
|
94 |
+ esac |
|
95 |
+ encoded+="${o}" |
|
96 |
+ done |
|
97 |
+ echo "${encoded}" # You can either set a return variable (FASTER) |
|
98 |
+ REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p |
|
99 |
+} |
|
100 |
+args=$1 |
|
101 |
+ |
|
102 |
+echo http://url/q?=$(rawurlencode "$args") |
|
103 |
+``` |
|
104 |
+Output example : |
|
105 |
+```bash |
|
106 |
+$ ./toto.sh "toto@gmail.com&truc=bidule&c=0x1234&tutu=%3" |
|
107 |
+http://url/q?=toto%40gmail.com%26truc%3dbidule%26c%3d0x1234%26tutu%3d%253 |
|
108 |
+``` |