]> git.plutz.net Git - shcgi/commitdiff
replace echo by the more unambiguous builtin printf
authorpaul <paul@plutz.net>
Fri, 10 Jul 2015 13:48:18 +0000 (13:48 +0000)
committerpaul <paul@plutz.net>
Fri, 10 Jul 2015 13:48:18 +0000 (13:48 +0000)
svn path=/trunk/; revision=7

action.sh
cgi.sh
index.cgi
page.sh

index 1f44ca10bf4c2a54c1cbdea7483fd2fd5ea9c1e5..f8faf1f6a8001fdabf9a414ed7e5190b86197f4f 100755 (executable)
--- a/action.sh
+++ b/action.sh
@@ -17,7 +17,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with Serve0.  If not, see <http://www.gnu.org/licenses/>. 
 
-ACTION="$(echo "$_GET[\"action\"]" |egrep '^[a-zA-Z0-9_-]+$')"
+ACTION="$(printf %s "$_GET[\"action\"]" |egrep '^[a-zA-Z0-9_-]+$')"
 ACTION="${_EXEC}/actions/${ACTION}.sh"
 
 if [ -x "$ACTION" ]; then
@@ -25,6 +25,6 @@ if [ -x "$ACTION" ]; then
   . $ACTION
 else
   debug "unable to execute $ACTION"
-  echo -n "Location: ?p=error\n\n"
+  printf "Location: ?p=error\n\n"
 fi
 
diff --git a/cgi.sh b/cgi.sh
index 37f4787dede71a492551a313863d6d92259399df..99942195cc4787bd551b1653c71c494a0146eb3d 100755 (executable)
--- a/cgi.sh
+++ b/cgi.sh
@@ -25,10 +25,10 @@ declare -A _REF
 
 cgi_get() {  # parse HTTP GET string
   debug "== CGI DATA: GET =="
-  echo "$QUERY_STRING" |tr '&' '\n' |while read query; do
-    key="$(echo -E "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
-    val="$(echo -E "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
-    _GET["$key"]="$(echo -e "$(echo -E "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g')")"
+  printf '%s\n' "$QUERY_STRING" |tr '&' '\n' |while read query; do
+    key="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
+    val="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
+    _GET["$key"]="$(printf "$(printf %s "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g')")"
     debug "_GET[$key] => $val"
   done
 }
@@ -36,9 +36,9 @@ cgi_get() {  # parse HTTP GET string
 cgi_post() {  # parse HTTP POST string
   debug "== CGI DATA: POST =="
   sed -u 1q |tr '&' '\n' |while read query; do
-    key="$(echo -E "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
-    val="$(echo -E "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
-    value="$(echo -e "$(echo -E "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g;')")"
+    key="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
+    val="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
+    value="$(printf "$(printf %s "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g;')")"
     if [ -n "$_POST[\"$key\"]" ]; then
       n=0
       while [ -n "$_POST[\"$key$n\"]" ]; do n=$(($n + 1)); done
@@ -52,14 +52,14 @@ cgi_post() {  # parse HTTP POST string
 
 cgi_refdata() { # Parse GET data from referer
   debug "== CGI DATA: REFERER =="
-  echo "$HTTP_REFERER" |cut -d'?' -f2- |tr '&' '\n' |while read query; do
-    key="$(echo -E "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
-    val="$(echo -E "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
-    _REF["$key"]="$(echo -e "$(echo -E "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g')")"
+  printf '%s\n' "$HTTP_REFERER" |cut -d'?' -f2- |tr '&' '\n' |while read query; do
+    key="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')"
+    val="$(printf %s "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')"
+    _REF["$key"]="$(printf "$(printf %s "$val" |sed 's:+: :g;s:\\:\\\\:g;s:%:\\x:g')")"
     debug "_REF[$key] => $val"
   done
 }
 
 urlsave(){
-  echo -E "$*" |sed 's:%:\%25:g;s:\?:\%3F:g;s:&:\%26:g;s:'\'':\%27:g;s: :\%20:g;s:!:\%21:g;s:(:\%28:g;s:):\%29:g;s:":\%22:g;'
+  printf %s "$*" |sed 's:%:\%25:g;s:\?:\%3F:g;s:&:\%26:g;s:'\'':\%27:g;s: :\%20:g;s:!:\%21:g;s:(:\%28:g;s:):\%29:g;s:":\%22:g;'
 }
index fada33d28e5e7a0bcb09a2e462f5e19ce2646023..af99fe150b67db0149b81858603d69e9a2b1c17d 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -36,7 +36,7 @@ _EXEC="${real%/shcgi/index.cgi}"  #execution directory
 # basic functions
 debug() { #change to false to disable debugging
   if [ "$DBG_ENABLED" = true -a -n "$*" ]; then
-    echo -E "$@" >>"$DBG_FILE"
+    printf '%s\n' "$*" >>"$DBG_FILE"
   elif [ "$DBG_ENABLED" = true -a -z "$*" ]; then
     tee -a "$DBG_FILE"
   elif [ -z "$*" ]; then
@@ -45,8 +45,8 @@ debug() { #change to false to disable debugging
 }
 
 die() {
-  debug "$@"
-  echo -E "$@" >>/dev/stderr
+  debug FATAL: "$*"
+  printf '%s\n' "$*" >&2
   exit 1
 }
 
diff --git a/page.sh b/page.sh
index 96f3fcc26f048924abad208e4c4c0f5c4cb953aa..d4e38cec88e2d79c3354feedde3bc74934ecd5cb 100755 (executable)
--- a/page.sh
+++ b/page.sh
 # You should have received a copy of the GNU Affero General Public License
 # along with shcgi.  If not, see <http://www.gnu.org/licenses/>. 
 
-echo -n "Content-Type: text/html;charset=utf-8\n\n"
+printf "Content-Type: text/html;charset=utf-8\n\n"
 
-PAGE="$(echo -E "$_GET[\"p\"]" |egrep '^[a-zA-Z0-9_-]+$')"
+PAGE="$(printf %s "$_GET[\"p\"]" |egrep '^[a-zA-Z0-9_-]+$')"
 PAGE="${_EXEC}/pages/${PAGE}.sh"
 [ -x "$PAGE" ] || PAGE="${_EXEC}/pages/error.sh"
 
 NAVIGATION() {
   for each in "${_EXEC}"/pages/*.sh; do
-    link="$(echo -E "$each" |sed -r "s:^.*/([^/]*)\.sh$:\1:")"
+    link="$(printf %s "$each" |sed -r "s:^.*/([^/]*)\.sh$:\1:")"
     title="$($each title)"
-    [ -n "$title" ] && echo -E "?p=$link $title"
+    [ -n "$title" ] && printf '%s\n' "?p=$link $title"
   done
 }