In Quoting constructs§
See primary documentation in context for Shell quoting with interpolation: qqx
If one wishes to use the content of a Raku variable within an external command, then the qqx
shell quoting construct should be used:
my $world = "there"; say qqx{echo "hello $world"}; # OUTPUT: «hello thereâ€Â»
Again, the output of the external command can be kept in a variable:
my $word = "cool"; my $option = "-i"; my $file = "/usr/share/dict/words"; my $output = qqx{grep $option $word $file}; # runs the command: grep -i cool /usr/share/dict/words say $output; # OUTPUT: «Cooleyâ€Cooley'sâ€Coolidgeâ€Coolidge'sâ€coolâ€...»
Be aware of the content of the Raku variable used within an external command; malicious content can be used to execute arbitrary code. See qqx
traps
See also run and Proc::Async
for better ways to execute external commands.