jaq: small tweaks and code-style - json2tsv - JSON to TSV converter
(HTM) git clone git://git.codemadness.org/json2tsv
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 7c73ed4db155770fb3c42edd396b894b209bdf41
(DIR) parent 6c4f4766a6151180fafe4f5d8d7e396e2a0d1876
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Thu, 1 Sep 2022 01:39:35 +0200
jaq: small tweaks and code-style
Diffstat:
M jaq | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
---
(DIR) diff --git a/jaq b/jaq
@@ -1,7 +1,6 @@
#!/bin/sh
-
nflag=""
-if test "$1" = "-n"; then
+if [ "$1" = "-n" ]; then
nflag="-n"
shift
fi
@@ -12,10 +11,10 @@ if [ $# -le 0 ]; then
fi
expr="$*"
-# simulate pipefail if JSON data is invalid.
+# POSIX way to simulate -o pipefail if JSON data is invalid.
statusfile=$(mktemp)
trap -- "rm -f \"${statusfile}\"" "EXIT"
{ json2tsv ${nflag} -r -F '\x1f' -R '\x1e'; echo $? >"${statusfile}"; } | \
LC_ALL=C awk "BEGIN { FS = \"\x1f\"; RS = \"\x1e\" }${expr}"
statuscode="$(cat "${statusfile}" 2>/dev/null)$?"
-test "${statuscode}" = "00"
+[ "${statuscode}" = "00" ]