You copied a line out of a pipeline log — that variable only exists inside the pipeline
Workflow managers set tool paths as environment variables ($BWA, $SAMTOOLS) that exist only while the workflow is running the task. Paste $BWA mem … into your own shell and the variable is empty, so the shell reads mem as the command name. This is a red herring — it tells you nothing about why the pipeline failed.
Ignore it and go back to the pipeline's own error. In Nextflow, open the Work dir: path printed just above the failure and read .command.err in full — the real reason is in there, usually before any long usage dump.