Format shell scripts with shfmt.

All changes in this patch were performed automatically with `shfmt` with
configuration flags specified in `.pre-commit-config.yaml`.

In addition to fixing whitespace the roundtrip through shfmt's AST also
transforms command substitutions

    `cmd`
    # becomes
    $(cmd)

and some redirects

    >&2 echo "msg"
    # becomes
    echo >&2 "msg"
This commit is contained in:
Benjamin Bannier 2021-11-24 22:48:46 +01:00
parent e0b4659488
commit 1f388e3f40
34 changed files with 369 additions and 379 deletions

View file

@ -2,4 +2,4 @@
#
# Default canonifier used with the tests in testing/btest/*.
`dirname $0`/diff-remove-timestamps
$(dirname $0)/diff-remove-timestamps

View file

@ -3,28 +3,27 @@
# Default canonifier used with the trace-based tests in testing/external/*.
if [ $# != 1 ]; then
echo "usage: `basename $0` <filename>"
echo "usage: $(basename $0) <filename>"
exit 1
fi
filename=`basename $1`
filename=$(basename $1)
addl="cat"
if [ "$filename" == "capture_loss.log" ]; then
addl="`dirname $0`/diff-remove-fractions"
addl="$(dirname $0)/diff-remove-fractions"
fi
if [ "$filename" == "ssh.log" ]; then
addl="`dirname $0`/diff-remove-fields remote_location"
addl="$(dirname $0)/diff-remove-fields remote_location"
fi
`dirname $0`/diff-remove-timestamps \
| `dirname $0`/diff-remove-uids \
| `dirname $0`/diff-remove-file-ids \
| `dirname $0`/diff-remove-x509-names \
| `dirname $0`/diff-sort-conn-service \
| `dirname $0`/diff-sort-set-elements \
| `dirname $0`/diff-sort \
| eval $addl
$(dirname $0)/diff-remove-timestamps |
$(dirname $0)/diff-remove-uids |
$(dirname $0)/diff-remove-file-ids |
$(dirname $0)/diff-remove-x509-names |
$(dirname $0)/diff-sort-conn-service |
$(dirname $0)/diff-sort-set-elements |
$(dirname $0)/diff-sort |
eval $addl

View file

@ -2,11 +2,11 @@
#
# Replace absolute paths with the basename.
if [ `uname` == "Linux" ]; then
sed="sed -r"
if [ $(uname) == "Linux" ]; then
sed="sed -r"
else
sed="sed -E"
sed="sed -E"
fi
$sed 's#/+#/#g' | \
$sed 's#/([^ :/]{1,}/){1,}([^ :/]{1,})#<...>/\2#g'
$sed 's#/+#/#g' |
$sed 's#/([^ :/]{1,}/){1,}([^ :/]{1,})#<...>/\2#g'

View file

@ -4,7 +4,7 @@
# prefix.
if [ $# != 1 ]; then
echo "usage: `basename $0` <field prefix>"
echo "usage: $(basename $0) <field prefix>"
exit 1
fi

View file

@ -3,4 +3,3 @@
# Replace fractions of double value (i.e., 3.14 -> 3.x).
sed 's/\.[0-9]\{1,\}/.X/g'

View file

@ -3,10 +3,10 @@
# Replace timestamps in the #start/end markers in logs.
# Get us "modern" regexps with sed.
if [ `uname` == "Linux" ]; then
sed="sed -r"
if [ $(uname) == "Linux" ]; then
sed="sed -r"
else
sed="sed -E"
sed="sed -E"
fi
$sed 's/^ *#(open|close).(19|20)..-..-..-..-..-..$/#\1 XXXX-XX-XX-XX-XX-XX/g'

View file

@ -3,10 +3,10 @@
# Replace anything which looks like timestamps with XXXs (including the #start/end markers in logs).
# Get us "modern" regexps with sed.
if [ `uname` == "Linux" ]; then
sed="sed -r"
if [ $(uname) == "Linux" ]; then
sed="sed -r"
else
sed="sed -E"
sed="sed -E"
fi
$sed -e 's/(^|[^0-9])([0-9]{9,10}\.[0-9]{1,8})/\1XXXXXXXXXX.XXXXXX/g' -e 's/^ *#(open|close).(19|20)..-..-..-..-..-..$/#\1 XXXX-XX-XX-XX-XX-XX/g'
$sed -e 's/(^|[^0-9])([0-9]{9,10}\.[0-9]{1,8})/\1XXXXXXXXXX.XXXXXX/g' -e 's/^ *#(open|close).(19|20)..-..-..-..-..-..$/#\1 XXXX-XX-XX-XX-XX-XX/g'

View file

@ -8,11 +8,11 @@ if [ "$TMP" == "" ]; then
TMP=/tmp
fi
tmp=$TMP/`basename $0`.$$.tmp
tmp=$TMP/$(basename $0).$$.tmp
cat >$tmp
echo "### NOTE: This file has been sorted with `basename $0`."
echo "### NOTE: This file has been sorted with $(basename $0)."
cat $tmp | grep ^#
cat $tmp | grep -v ^# | sort -s

View file

@ -2,14 +2,14 @@
#
# Just writes the arguments and stdin to a file, to compare with diff
echo "------- cmdline args -----------" >> sendmail.out
echo "$*" >> sendmail.out
echo "----------- stdin --------------" >> sendmail.out
echo "------- cmdline args -----------" >>sendmail.out
echo "$*" >>sendmail.out
echo "----------- stdin --------------" >>sendmail.out
while IFS= read -r line; do
# Strip out the user agent, which is version dependent
if [[ $line == "User-Agent: Zeek/"* ]]; then
printf 'User-Agent: Zeek/$zeek_version()\n' >> sendmail.out
printf 'User-Agent: Zeek/$zeek_version()\n' >>sendmail.out
else
printf '%s\n' "$line" >> sendmail.out
printf '%s\n' "$line" >>sendmail.out
fi
done

View file

@ -41,8 +41,8 @@ if [ "$file_hash" != "$head_hash" ]; then
read -p "[Y/n] " choice
case "$choice" in
n|N) echo "Skipped '$repo_base'";;
*) echo $head_hash > $hash_file && git add $hash_file && echo "Updated '$file_base'";;
n | N) echo "Skipped '$repo_base'" ;;
*) echo $head_hash >$hash_file && git add $hash_file && echo "Updated '$file_base'" ;;
esac
else
echo " none"

View file

@ -3,8 +3,8 @@
# Sleeps until a file comes into existence.
if [[ $# -ne 2 ]]; then
>&2 echo "usage: $0 <file to wait for> <max secs to wait>"
exit 1
echo >&2 "usage: $0 <file to wait for> <max secs to wait>"
exit 1
fi
wait_file=$1
@ -12,13 +12,12 @@ max_wait=$2
wait_count=0
while [[ ! -e $wait_file ]]; do
let "wait_count += 1"
let "wait_count += 1"
if [[ $wait_count -ge $max_wait ]]; then
>&2 echo "error: file '$wait_file' does not exist after $max_wait seconds"
exit 1
fi
if [[ $wait_count -ge $max_wait ]]; then
echo >&2 "error: file '$wait_file' does not exist after $max_wait seconds"
exit 1
fi
sleep 1
sleep 1
done