Execution of external commands or binaries is different in mshell. Instead of it being the main syntactical construct, in mshell you build up a list of arguments, and then at a time of your choosing, you execute it.
For example:
['my-program' 'arg1' 'arg2'];
Often there are different things you want out of your execution,
or you want different behavior depending on the exit code.
mshell gives you full flexibility to decide with concise syntax.
To initiate execution, you use one of 3 operators:
;: Execute command, always continue. Don't provide any information on the exit code.!: Execute command, but stop the running script execution on any non-zero exit code.?: Execute command, leaving the exit code integer on the stack.
['false']; # mshell will continue past this point
['true']! # Will execute and continue because of 0 exit code
['my-command']? exitCode!
$"Exit code was {@exitCode}" wl
The other choice you often have when executing commands is what to do with the standard output.
Sometimes you will want to redirect it to a file, other times you will want to leave the contents on the stack to process further.
For that, you use the > and * operators.
[yourCommand] `fileToRedirectTo` > ! # Redirects the output to the file.
[yourCommand] * ! # Puts all of stdout on the stack as a string.
[yourCommand] *b ! # Puts all of stdout on the stack as a binary.
You can do similar things with standard error.
[yourCommand] ^ ! # Puts all of stderr on the stack as a string.
[yourCommand] ^b ! # Puts all of stderr on the stack as a binary.
If you want to put both standard output and standard error onto the stack, you can do that. Standard output will always be pushed first, and then standard error.
So the following are equivalent:
[yourCommand] *b ^b ! # Order here does not matter
[yourCommand] ^b *b !
Use < to feed data into stdin. The type of the value on top of the stack determines how the input is provided.
String values are encoded as UTF-8 and streamed as text.
[wc -l] "line 1\nline 2\n" < ; # Counts the lines from the provided string
Path values open the referenced file and stream its contents.
[wc -l] `myfile.txt` < ; # Equivalent to shell input redirection from a file
Binary values are written directly without any string conversion.
[md5sum] `binary_stdin.bin` readFileBytes < ; # Streams raw bytes into the command