How to check whether an external program is available for running via Raku?
In shell, type command is to be used, e.g:
if type trash-put
then trash-put delete-me
else rm delete-me
fi
You can't run 'type', 'trash-put' in Raku since type is a shell builtin.
You can, though, run 'sh', '-c', 'type trash-put' or shell 'type trash-put', so Raku equivalent would be:
if ! run( 'sh', '-c', 'type trash-put', :!out ).exitcode {
# if ! shell( 'type trash-put', :!out ).exitcode { # shell alternative to run
run 'trash-put', 'delete-me';
} else {
unlink 'delete-me'.IO;
}
but I wonder whether there are any better ways.
The question is not constrained to deleting files, other use-cases need an answer too: prefer curl over wget or browser1 over browser2 or $VISUAL over $EDITOR etc.