Safe Haskell | Safe-Infered |
---|
HsShellScript.Shell
Documentation
Arguments
:: String | name or path of the executable |
-> [String] | command line arguments |
-> String | shell command |
Generate command (for a shell) which corresponds to the specified program
name and argument list. The program name and arguments are the usual
parameters for calling an external program, like when using
runProcess
or run
. The generated shell command
would achieve the same effect. The name and the arguments are properly
quoted, using shell_quote
.
Note: The quoted strings are correctly recognized in shell scripts. But the shell bash has an annoying history expansion "feature", which causes
it to choke on exclamation marks, when in interactive mode, even when quoted with double quotes. You can turn it off with set +o histexpand
.
shell_quote :: String -> StringSource
Quote shell metacharacters.
This function quotes strings, such that they are not misinterpreted by the shell. It tries to be friendly to a human reader - when special characters are present, then the string is quoted with double quotes. If not, it is left unchanged.
The list of exacly which characters need to be quoted has been taken
from the bash source code. Bash in turn, implements POSIX 1003.2. So the
result produced should be correct. From the bash info pages:
"... the rules for evaluation and quoting are taken from the POSIX
1003.2 specification for the standard
Unix shell."
Note: The quoted strings are correctly recognized in shell scripts. But the shell bash has an annoying history expansion "feature", which causes
it to choke on exclamation marks, when in interactive mode, even when quoted with double quotes. You can turn it off with set +o histexpand
.
See quote
.
quote0 :: String -> StringSource
Quote special characters inside a string for the shell
This quotes special characters inside a string, such that it is recognized as one string by the shell when enclosed in double quotes. Doesn't add the double quotes.
Note: The quoted strings are correctly recognized in shell scripts. But the shell bash has an annoying history expansion "feature", which causes
it to choke on exclamation marks, when in interactive mode, even when quoted with double quotes. You can turn it off with set +o histexpand
.
See quote
, shell_quote
.
quote :: String -> StringSource
Quote a string for the shell
This encloses a string in double quotes and quotes any special characters inside, such that it will be recognized as one string by a shell. The double quotes are added even when they aren't needed for this purpose.
Note: The quoted strings are correctly recognized in shell scripts. But the shell bash has an annoying history expansion "feature", which causes
it to choke on exclamation marks, when in interactive mode, even when quoted with double quotes. You can turn it off with set +o histexpand
.
See quote0
, shell_quote
.