Can't run subshell command within `target_interpreter`
I'm trying to paste target_bin in the middle of target_interpreter command using subshell and xargs approaches:
# subshell
sh -c 'mit-scheme --load $0 --eval '((lambda () (main) (exit)))''
# xargs
xargs -i mit-scheme --load {} --eval '((lambda () ((main) (exit)))'
--loadshould be placed before--eval, sincemainshould be loaded before calling it. The command works fine if I do build step manually.
Can you help me to understand how to do it properly or is it even possible?
I'm very impressed with scriptisto. You have developed a very powerful tool.
P.S. I see chiken and racket templates, which are easily to use, but I can't find
sc-macro-transformerprocedure in chicken (and its eggs too) which is necessary for me, and racket language itself seems too complex at this moment.
Expected Behavior
target_interpreter command executed with target_bin passed as first argument.
Actual Behavior
| Approach | Result |
|---|---|
sh |
--load: 1: Syntax error: Unterminated quoted string |
bash |
--load: -c: line 1: unexpected EOF while looking for matching `'' |
zsh |
zsh:1: unmatched ' |
xargs |
freezes waiting for arguments |
Steps to Reproduce the Problem
- Create script "script.scm" file with the following content:
#! /usr/bin/env scriptisto ;; scriptisto-begin ;; script_src: script.scm ;; build_cmd: mit-scheme --eval '(cf "script")' ;; target_bin: ./script.com ;; # Trying to use subshell: ;; target_interpreter: sh -c 'mit-scheme --load $0 --eval '((lambda () (main) (exit)))'' ;; # Trying to use xargs: ;; # target_interpreter: xargs -i mit-scheme --load {} --eval '((lambda () ((main) (exit)))' ;; scriptisto-end (define (main) (write-line "Hello World from MIT/GNU Scheme")) -
chmod +x ./script.scm -
./script.scm - Try different
target_interpreteroptions (un)commenting lines in build instructions.
Specifications
- Version: 2.2.0 (current last version from Crates.io)
- Platform: Linux amd64 (
x86_64-unknown-linux-gnutaget)
Hi,
I tried debugging a bit with
RUST_LOG=debug cargo run -- ./script.scm
It makes debug build and enables logging. The tool ends up running execvp with
Running exec "sh", Args: ["sh", "-c", "'mit-scheme", "--load", "$0", "--eval", "'((lambda", "()", "(main)", "(exit)))''", "/home/user/.cache/scriptisto/bin/home/user/Projects/scriptisto/script.scm/script.com"]
target_interpreter is not very sophisticated, it does split_ascii_whitespace, which just cuts your command in pieces and sends it to execvp. It does not really handle escaping as expected. Maybe it could be fixed
Instead of trying to use something sophisticated in target_interpreter, I would instead just go with a simple shell script. It is a bit longer, but you don't have to struggle with how scriptisto slices the command line.
The idea is along the lines of
#! /usr/bin/env scriptisto
;; scriptisto-begin
;; script_src: script.scm
;; build_cmd: mit-scheme --eval '(cf "script")' && chmod +x ./run.sh
;; target_bin: ./run.sh
;; # Trying to use subshell:
;; files:
;; - path: ./run.sh
;; content: |
;; mit-scheme --load $(dirname $0)/script.com --eval '((lambda () (main) (exit)))'
;; scriptisto-end
(define (main) (write-line "Hello World from MIT/GNU Scheme"))
I hope it helps