command not available in bash script Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of command not available in bash script without wasting too much if your time.

The question is published on by Tutorial Guruji team.

My company has a custom tool we install in Linux to upload files to a server (among other things) called oTools. When I open a new Terminal, I can run (from any folder) oTools upload file and file is uploaded to the server.

However, the tool doesn’t have an option to upload several files at once. So I’m trying to build a bash script to do that. Here is the code I built

#!/bin/sh

for file in ./folder/*
do
  oTools upload $file
done

But I’m having the following error:

./upload-all.sh: oTools: not found

I’ve checked my file .bashrc and it contains the path to oTools:

alias oTools="/home/user/folder/oTools-cli"

I’ve tried also to put the complete path on my script (the path above, that is on .bashrc file), but I’m getting the same issue. I tried doing the same code using ls instead of my installed tool and it worked…

So, how can I make bash script to recognize my custom tool?

Answer

When you write a script, it doesn’t typically pull in your aliases.

You might consider specifying the command explicitly in your script:

#!/bin/sh
oTools="/home/user/folder/oTools-cli"
for file in ./folder/*
do
    ${oTools} upload "${file}"
done
We are here to answer your question about command not available in bash script - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji