Simplified a bit. master
authorFrancois Fleuret <francois@fleuret.org>
Mon, 3 Aug 2020 17:35:21 +0000 (19:35 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Mon, 3 Aug 2020 17:35:21 +0000 (19:35 +0200)
xremote.sh

index 478a773..bcb33ca 100755 (executable)
@@ -70,7 +70,8 @@ xremote.sh [--help] [-h <remote_host>] [-d <remote_dir>] [-r <local_result_dir>]
   main executable and post-run commands are ignored
 
   If the -r option is provided, the result files specified with
-  @XREMOTE_GET will be downloaded there.
+  @XREMOTE_GET will be downloaded there instead of the current
+  directory.
 
   If no argument is provided to @XREMOTE_HOST, and the -h option is
   not specified, the environment variable \$XREMOTE_HOST is used
@@ -170,8 +171,8 @@ do
     if [[ "${line}" =~ '@XREMOTE' ]]
     then
 
-        label=$(echo "${line}" | sed -e 's/^.*@XREMOTE_\([^:]*\):.*$/\1/')
-        value=$(echo "${line}" | sed -e 's/^.*@XREMOTE_[^:]*: *\(.*\)$/\1/')
+        label=$(sed -e 's/^.*@XREMOTE_\([^:]*\):.*$/\1/' <<<"${line}")
+        value=$(sed -e 's/^.*@XREMOTE_[^:]*: *\(.*\)$/\1/' <<<"${line}")
 
         case "${label}" in
 
@@ -260,12 +261,14 @@ else
     RESULT_DIR="."
 fi
 
+[[ "${ARG_RESULT_DIR}" ]] && mkdir -p "${ARG_RESULT_DIR}"
+
 while read line
 do
     if [[ "${line}" =~ '@XREMOTE' ]]
     then
-        label=$(echo "${line}" | sed -e 's/^.*@XREMOTE_\([^:]*\):.*$/\1/')
-        value=$(echo "${line}" | sed -e 's/^.*@XREMOTE_[^:]*: *\(.*\)$/\1/')
+        label=$(sed -e 's/^.*@XREMOTE_\([^:]*\):.*$/\1/' <<<"${line}")
+        value=$(sed -e 's/^.*@XREMOTE_[^:]*: *\(.*\)$/\1/' <<<"${line}")
         case "${label}" in
             POST)
                 check_remote_is_defined