diff options
Diffstat (limited to 'bin/ax.sh')
-rw-r--r-- | bin/ax.sh | 17 |
1 files changed, 6 insertions, 11 deletions
@@ -3,8 +3,8 @@ # Count arguments case $# in - # If one argument, we assume format is %s - 1) form=%s expr=$1 ;; + # If one argument, we assume format is %s\n + 1) form='%s\n' expr=$1 ;; # If two arguments, first is format, second expression 2) form=$1 expr=$2 ;; @@ -16,12 +16,7 @@ case $# in ;; esac -# Form program -prog=$(printf ' - BEGIN { - printf "%s\\n", %s - } -' "$form" "$expr") - -# Run program -awk "$prog" +# Important note: there's little stopping the user from putting a fully-fledged +# Awk program into the expression; don't use this anywhere that code injection +# could wreck your life. See manual page ax(1df). +awk -v form="$form" 'BEGIN{printf form,('"$expr"');exit}' |