commit 0d0177c5f78ce0255dbd576947fabd26b64bc436
parent abebc2ca1691190d96cb0ae0a527cfc6d18f1cf8
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 17 Oct 2022 16:17:05 +0200
Make shell scripts conform to POSIX
Diffstat:
2 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/src/dump_netcdf_data.sh b/src/dump_netcdf_data.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# Copyright (C) 2018 |Meso|Star> (contact@meso-star.com)
#
@@ -14,25 +14,25 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
set -e
-set -o pipefail
if [ $# -lt 2 ]; then
>&2 echo "Usage: $0 VAR-NAME LES-NETCDF "
- exit -1
+ exit 1
fi
-if [ ! -f $2 ]; then
+if [ ! -f "$2" ]; then
>&2 echo "\"$2\" is not a valid file."
- exit -1
+ exit 1
fi
-name=$(basename $2)
+name=$(basename "$2")
name=${name%.*}
-ncdump -v $1 $2 \
+ncdump -v "$1" "$2" \
| sed -n "/^ *$1 *=/,\$p" \
| sed "s/^ *$1 *= *//g" \
| sed 's/[;} ]//g' \
| sed 's/,/\n/g' \
- | sed '/^ *$/d' > ${name}_${1}
+ | sed '/^ *$/d' > "${name}_${1}"
diff --git a/src/dump_netcdf_desc.sh b/src/dump_netcdf_desc.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# Copyright (C) 2018 |Meso|Star> (contact@meso-star.com)
#
@@ -15,33 +15,32 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. */
set -e
-set -o pipefail
if [ $# -lt 1 ]; then
- >&2 echo "Usage: $0 -NAME LES-NETCDF "
- exit -1
+ >&2 printf "Usage: %s -NAME LES-NETCDF\n" "$0"
+ exit 1
fi
-dimensions=$(ncdump -h $1 | sed '/^ *variables/,$d' | sed '1,2d')
-nx=$(echo $dimensions | sed -n 's/^.*W_E_direction *= *\([0-9]\+\) *;.*$/\1/p')
-ny=$(echo $dimensions | sed -n 's/^.*S_N_direction *= *\([0-9]\+\) *;.*$/\1/p')
-nz=$(echo $dimensions | sed -n 's/^.*vertical_levels *= *\([0-9]\+\) *;.*$/\1/p')
-ntimes=$(echo $dimensions | sed -n 's/^.*time *= *\([0-9]\+\) *;.*$/\1/p')
+dimensions=$(ncdump -h "$1" | sed '/^ *variables/,$d' | sed '1,2d')
+nx=$(echo "${dimensions}" | sed -n 's/^.*W_E_direction *= *\([0-9]\{1,\}\) *;.*$/\1/p')
+ny=$(echo "${dimensions}" | sed -n 's/^.*S_N_direction *= *\([0-9]\{1,\}\) *;.*$/\1/p')
+nz=$(echo "${dimensions}" | sed -n 's/^.*vertical_levels *= *\([0-9]\{1,\}\) *;.*$/\1/p')
+ntimes=$(echo "${dimensions}" | sed -n 's/^.*time *= *\([0-9]\{1,\}\) *;.*$/\1/p')
-if [ -z "$ntimes" ]; then
- ntimes=$(echo $dimensions | sed -n 's/^.*time *=.*\/\/ *(\([0-9]\+\) currently).*$/\1/p')
+if [ -z "${ntimes}" ]; then
+ ntimes=$(echo "${dimensions}" | sed -n 's/^.*time *=.*\/\/ *(\([0-9]\{1,\}\) currently).*$/\1/p')
fi
-if [ -z "$nx" -o -z "$ny" -o -z "$nz" -o -z "$ntimes" ]; then
- >&2 echo $0: Error retrieving the dimensions of \"$1\"
- exit -1
+if [ -z "${nx}" ] || [ -z "${ny}" ] || [ -z "${nz}" ] || [ -z "${ntimes}" ]; then
+ >&2 printf "%s: Error retrieving the dimensions of \"%s\"\n" "$0" "$1"
+ exit 1
fi
-name=$(basename $1)
+name=$(basename "$1")
name=${name%.*}
{
- echo $nx
- echo $ny
- echo $nz
- echo $ntimes
-} > ${name}_desc
+ echo "${nx}"
+ echo "${ny}"
+ echo "${nz}"
+ echo "${ntimes}"
+} > "${name}_desc"