samtools command not found in bash script
1
0
Entering edit mode
8 weeks ago
Meghan.T • 0

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

cross posted here: https://stackoverflow.com/questions/79020546/samtools-command-not-found-in-bash-script

samtools alias • 387 views
ADD COMMENT
1
Entering edit mode

"How to fix a 'Command not found' error in Linux" https://www.redhat.com/sysadmin/fix-command-not-found-error-linux

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
2
Entering edit mode
8 weeks ago
cfos4698 ★ 1.1k

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
ADD COMMENT

Login before adding your answer.

Traffic: 2526 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6