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


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

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?

  • 3
    Double-quote that variable "$file" when you use it. Otherwise your code will break unexpectedly when you use a filename that contains a character special to the shell. Mar 14, 2018 at 21:51

3 Answers 3


You're facing at least two problems:

  • Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt.

  • .bashrc usually holds configuration for interactive shells, not for scripts (aka non-interactive shells).

There are some solutions:

# Set expand_aliases option and add the alias (in your script)
shopt -s expand_aliases
alias oTools="/home/user/folder/oTools-cli"

# Create a function instead of an alias (in your script)
oTools() { /home/user/folder/oTools-cli "$@"; }

# Add /home/user/folder to your PATH (in your .profile)
  • Some of this may fail because the OP has declared #!/bin/sh rather than #!/bin/bash. Mar 14, 2018 at 21:52
  • expand_aliases I learn something useful every day....
    – RonJohn
    Mar 14, 2018 at 22:49

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

You might consider specifying the command explicitly in your script:

for file in ./folder/*
    ${oTools} upload "${file}"

This is an issue i ran into when running scripts via cron. I am not sure if it applies here, but here try adding your path at the beginning of the script. Something like...


  • 2
    You want to set PATH=/your/path:$PATH perhaps, or more safely PATH=/your/path:/usr/bin:/bin. Otherwise, you won't have access to standard programs (cat, ls, find, sed, awk...).
    – NickD
    Mar 14, 2018 at 21:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .