In Quoting constructs§
See primary documentation in context for Shell quoting: qx
To run a string as an external program, not only is it possible to pass the string to the shell
or run
functions but one can also perform shell quoting. There are some subtleties to consider, however. qx
quotes don't interpolate variables. Thus
my $world = "there"; say qx{echo "hello $world"}
prints simply hello
. Nevertheless, if you have declared an environment variable before calling raku
, this will be available within qx
, for instance
WORLD="there" raku > say qx{echo "hello $WORLD"}
will now print hello there
.
The result of calling qx
is returned, so this information can be assigned to a variable for later use:
my $output = qx{echo "hello!"}; say $output; # OUTPUT: «hello!»
See also shell, run and Proc::Async
for other ways to execute external commands.