#!/bin/sh #============================================================ # check_your_awk version 0.1 (2011-12-04) # written by cleemy desu wayo # # This work is dedicated to the public domain. # # References: # http://blog.livedoor.jp/corbie/ #============================================================ LANGUAGE=C LC_ALL=C LANG=C check_your_awk_list="nawk::nawk gawk::gawk mawk::mawk busybox:awk:busybox original-awk::original-awk " check_your_awk_exec () { if [ -z "${4}" ] ;then check_your_awk_exec_mode="0" else check_your_awk_exec_mode="${4}" fi printf "%s\n" "============================================" printf "%s\n" "${2}" printf "%s\n" "============================================" if [ "${check_your_awk_exec_mode}" = "1" ];then printf "[code]\nawk %s\n\n" "'${3}' | od -t x1 | head -1" elif [ "${check_your_awk_exec_mode}" = "2" ];then printf "[code]\n%s\n\n" "printf \"%s\" \"a\" | awk '${3}'" else printf "[code]\nawk %s\n\n" "'${3}'" fi printf "%s" "${1}" | while read s ;do check_your_awk_exec_command=`printf "%s" "${s}" | sed -e 's/:.*//'` check_your_awk_exec_command_param=`printf "%s" "${s}" | sed -e 's/.*:\(.*\):.*/\1/'` check_your_awk_exec_id=`printf "%s" "${s}" | sed -e 's/.*://'` if ! [ -z "`which "${check_your_awk_exec_command}" | grep -e '^/'`" ] ;then printf "[%s]\n" "${check_your_awk_exec_id}" if [ -z "${check_your_awk_exec_command_param}" ];then if [ "${check_your_awk_exec_mode}" = "1" ];then "${check_your_awk_exec_command}" "${3}" 2>&1 | od -t x1 | head -1 elif [ "${check_your_awk_exec_mode}" = "2" ];then printf "%s" "a" | "${check_your_awk_exec_command}" "${3}" 2>&1 else "${check_your_awk_exec_command}" "${3}" 2>&1 fi else if [ "${check_your_awk_exec_mode}" = "1" ];then "${check_your_awk_exec_command}" "${check_your_awk_exec_command_param}" "${3}" 2>&1 | od -t x1 | head -1 elif [ "${check_your_awk_exec_mode}" = "2" ];then printf "%s" "a" | "${check_your_awk_exec_command}" "${check_your_awk_exec_command_param}" "${3}" 2>&1 else "${check_your_awk_exec_command}" "${check_your_awk_exec_command_param}" "${3}" 2>&1 fi fi printf "\n" fi done printf "\n" } printf "%-18s: %s\n" "version" "check_your_awk version 0.1 (2011-12-04)" printf "%-18s: " "time" date "+%Y-%m-%d %H:%M:%S" 2>&1 | tr -d '\n' printf "\n" printf "%-18s: " "uname" if ! [ -z `which uname` ] ;then uname -a 2>&1 | tr -d '\n' fi printf "\n" printf "%s" "${check_your_awk_list}" | while read s ;do check_your_awk_command=`printf "%s" "${s}" | sed -e 's/:.*//'` if [ "${check_your_awk_command}" = "busybox" ] ;then check_your_awk_version=`busybox 2>&1 | head -1` elif [ "${check_your_awk_command}" = "mawk" ] ;then check_your_awk_version=`mawk -W version 2>&1 | head -1` else check_your_awk_version=`"${check_your_awk_command}" --version 2>&1 | head -1` fi printf "%-18s: %s\n" "${check_your_awk_command}" "${check_your_awk_version}" done printf "\n\n" check_your_awk_exec "${check_your_awk_list}" \ 'func' \ 'func a(){ print "hello" } BEGIN{ a() }' check_your_awk_exec "${check_your_awk_list}" \ 'length()' \ 'BEGIN{ a[0]=1; a[1]=2; print length(a) }' check_your_awk_exec "${check_your_awk_list}" \ 'close()' \ 'BEGIN{ f="h9g7Tnw3"; while (getline s < f > 0) {print s;}; print "open done."; close(f); print "close done." }' check_your_awk_exec "${check_your_awk_list}" \ 'regex character class' \ 'BEGIN{ s="a b"; if (s ~ /a[[:space:]]b/) {print s} else {print "unmatched"} }' check_your_awk_exec "${check_your_awk_list}" \ 'hyphen in regex 1' \ 'BEGIN{ s="a-b"; if(s ~ /a[a\-a]b/){print s} else {print "unmatched"} }' check_your_awk_exec "${check_your_awk_list}" \ 'hyphen in regex 2' \ 'BEGIN{ s="a-b"; if(s ~ /a[\#\-\#]b/){print s} else {print "unmatched"} }' check_your_awk_exec "${check_your_awk_list}" \ 'backslash in regex' \ 'BEGIN{ s="a(b)c"; if(s ~ "a\(b\)c"){print s} else {print "unmatched"} }' check_your_awk_exec "${check_your_awk_list}" \ 'backslash in sub() and gsub()' \ 'BEGIN{ s="\\"; sub(/\\/, "\\\\", s); print s }' check_your_awk_exec "${check_your_awk_list}" \ 'gsub()' \ 'BEGIN{ s="aaabbbccc"; gsub(/^[^b]*/, "", s); print s }' check_your_awk_exec "${check_your_awk_list}" \ 'output null byte 1' \ 'BEGIN{ print "\0" }' '1' check_your_awk_exec "${check_your_awk_list}" \ 'output null byte 2' \ 'BEGIN{ printf "%c", "\0" }' '1' check_your_awk_exec "${check_your_awk_list}" \ 'output null byte 3' \ 'BEGIN{ printf "%c", 0 }' '1' check_your_awk_exec "${check_your_awk_list}" \ 'number or string' \ '{ s=$1; sub(/a/, "10", s); r = (s > 5) ? "true" : "false"; print r } ' '2'