October 2011
Intermediate to advanced
300 pages
5h 51m
English
If you need to insert values into a command line, they often need to be quoted, especially if they contain spaces. The shellquote function will take any number of arguments, including arrays, and quote each of the arguments and return them all as a space-separated string that you can pass to commands.
In this example, we would like to set up an exec resource which will rename a file, but both the source and the target name contain spaces, so they need to be correctly quoted in the command line.
$source = "Hello Jerry"
$target = "Hello... Newman"
$argstring = shellquote( $source, $target )
$command = "/bin/mv ${argstring}"
notify { $command: }
notice: /bin/mv ...Read now
Unlock full access