quote qx

Documentation for quote qx, assembled from the following types:

language documentation Quoting Constructs

From Quoting Constructs

(Quoting Constructs) quote 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 perl6, this will be available within qx, for instance

WORLD="there" perl6
> 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.