In my ~/.bashrc
file reside two definitions:
commandA
, which is an alias to a longer pathcommandB
, which is an alias to a Bash script
I want to process the same file with these two commands, so I wrote the following Bash script:
#!/bin/bash
for file in "$@"
do
commandA $file
commandB $file
done
Even after logging out of my session and logging back in, Bash prompts me with command not found
errors for both commands when I run this script.
What am I doing wrong?
Best Answer
First of all, as ddeimeke said, aliases by default are not expanded in non-interactive shells.
Second,
.bashrc
is not read by non-interactive shells unless you set theBASH_ENV
environment variable.But most importantly: don't do that! Please? One day you will move that script somewhere where the necessary aliases are not set and it will break again.
Instead set and use variables as shortcuts in your script: