Skip to main content

sh

Function sh 

Source
pub fn sh(script: &str) -> Result<String>
Expand description

Run a run= script and return its stdout.

Executed with sh -c, which is the language the spec format’s run= is written in — the reference examples use pipelines, ; sequences and shebang scripts. On Windows, where a POSIX shell is not guaranteed, a missing sh falls back to cmd /c; that runs a plain command invocation but none of the above, so a spec meant to work there should keep run= to a single command.

stdin is closed and stderr is inherited, so a script cannot stall a completion waiting for input but can still say why it failed. __USAGE is set to the usage version, letting a script tell that it was invoked by usage.

Output that is not valid UTF-8 is an error, not a panic and not a lossy conversion. The cmd /c fallback in particular emits the console code page, which is not UTF-8 outside English locales, and a mount’s output is parsed as a spec — replacement characters there would resurface as a baffling KDL syntax error instead of an encoding one.