So I wrote a bash code in which I am using samtools.
#!/bin/bash
# some
# code
samtools view -bS input.sam out.bam
while running this, I get the error :
samtools: command not found.
but I can run samtools fine in the terminal. I looked to the .bashrc file and looks like there is an alias for samtools: alias samtools='samtools_0.1.18' . I added this line at the begining of my code, after #!/bin/bash, but still I get the same error: samtools: command not found.
Any Idea how to fix this? Thanks in advance
Thank you for your reply. for me, samtools works fine in terminal, but not in the bash code, so I don't think there's anything wrong with path or the installation of command itself.
In your terminal, type which samtools. This will give you the full path to samtools. Use that full path in your script. For example:
$ which samtools
/Users/charles/miniforge3/envs/samtools/bin/samtools
For an aliased program like yours, it'll be like this:
$ alias samtools=/Users/charles/miniforge3/envs/samtools/bin/samtools
$ which samtools
samtools: aliased to /Users/charles/miniforge3/envs/samtools/bin/samtools
I'd then use:
#!/bin/bash
# some
# code
/Users/charles/miniforge3/envs/samtools/bin/samtools view -bS input.sam out.bam
This is a short term solution. If you want it 'globally' available without this workaround, you should determine where it is installed/located (as per the above), then ensure that location is in your path. For example, in this example:
# assuming for this case that samtools is in /Users/charles/Programs/samtools/bin
echo 'export PATH=${PATH}:/Users/charles/Programs/samtools/bin' >> ~/.bashrc
source ~/.bashrc
"How to fix a 'Command not found' error in Linux" https://www.redhat.com/sysadmin/fix-command-not-found-error-linux
Thank you for your reply. for me, samtools works fine in terminal, but not in the bash code, so I don't think there's anything wrong with path or the installation of command itself.