Replace __STAR__ in sh* eval and quote result.
authorChris McCormick <chris@mccormick.cx>
Mon, 2 Dec 2019 10:08:24 +0000 (18:08 +0800)
committerChris McCormick <chris@mccormick.cx>
Mon, 2 Dec 2019 12:35:25 +0000 (20:35 +0800)
This supercedes #470 and includes #471.
This fixes some edge cases when passing an asterisk to an sh* interop call.
Before this fix mal would pass the string with any wildcard character converted to __STAR__ when passing to the subcommand.
For example `(sh* "ls *")` would become `ls __STAR__` when executed.
See the tests for examples of where this would fail to do what the user expects.
See also: https://github.com/chr15m/flk/issues/1

bash/stepA_mal.sh
bash/tests/stepA_mal.mal

index 2c4de6d..c6c6587 100755 (executable)
@@ -165,9 +165,11 @@ EVAL () {
         sh__STAR__)  EVAL "${a1}" "${env}"
               local output=""
               local line=""
+              r="${ANON["${r}"]}"
+              r="${r//__STAR__/*}"
               while read -r line || [ -n "${line}" ]; do
                 output="${output}${line}"$'\n'
-              done < <(eval ${ANON["${r}"]})
+              done < <(eval "${r}")
               _string "${output%$'\n'}"
               return ;;
         try__STAR__) EVAL "${a1}" "${env}"
index a330946..f977055 100644 (file)
@@ -24,3 +24,9 @@
 
 (sh* "echo hello; echo foo; echo yes;")
 ;=>"hello\nfoo\nyes"
+
+(sh* "grep -oE '\[.*!\]' core.sh")
+;=>"[reset!]\n[swap!]"
+
+(sh* "ls cor*.sh")
+;=>"core.sh"