command not available in bash script

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

Leave a Reply

Your email address will not be published. Required fields are marked *