I'm trying to write a ZSH script so I can run an arbitrary script (say, a JavaScript app) and open the script's output as a file in another application (my IDE). Here, my thinking is to invoke it ./myscript.sh $(node main.js)
. Content of myscript.sh
right now:
#!/bin/zsh
TEMPFILE=$(mktemp /tmp/atom.XXXX)
echo $1 > $TEMPFILE
ide --file=$TEMPFILE
I'm running into trouble on the echo
line. The application's output is markup, so it has a variety of whitespace, backticks, (single|double) quotation marks, alphanumeric char, symbols, and newlines in it.
I understand the issues have to do with the backticks and quotation mark species in the app's output. Some dummy output:
# Weightlifting Workout A
Bodyweight: 165
| Lift | ||| 1RM (lb) |
|---| ---:|---:|---:| :-- |
|**Squats**|100x5<br>*0.61xBW*|90x6<br>*0.55xBW*|80x8<br>*0.48xBW*|112.5 |
|**Deadlift**|250x2<br>*1.52xBW*|||257.1 |
I imagine the fix is that I need to wrap something around the $1
, but not sure what. The newlines in the JavaScript output is messing with echo
.
I've tried combinations of ./myscript.sh $(node main.js)
, ./myscript.sh "node main.js"
, ./myscript.sh "$(node main.js)"
with echo $1 > file
, echo $($1) > file
, etc.
playing around with passing the app's output as the zsh argument or passing the app's name as the zsh argument and then the zsh script executing the app's name.
Can't figure out how to get this working without running into an error like "command not found: node main.js" or "command not found: #" or something like that.