0

I have a shell script that runs a command:

#!/bin/bash
r my custom command

Now I have a folder on my computer ~/myuser/tools/r/my.sh

But when I run the file it gives me "r: command not found" which is on that line I provided above.

However, when I just enter r my custom command into the terminal, it does run. It just doesn't run from the shell script.

alias r="/myuser/tools/r/my.sh"

I've also confirmed I am running in bash mode and not Zsh

I'm running macos Big Sur on a silicon M1 MBP.

Nathan Leggatt
  • 398
  • 1
  • 6
  • 18
  • 2
    This question concerns an alias, not a binary, so `PATH` is irrelevant; the problem is that aliases are not expanded in scripts (by default), only in interactive shells. You need to either enable them or use a function instead of an alias. ["bash script not reading alias in bashrc"](https://stackoverflow.com/questions/17725236/bash-script-not-reading-alias-in-bashrc) and ["How to use aliases defined in .bashrc in other scripts?"](https://stackoverflow.com/questions/5240755/how-to-use-aliases-defined-in-bashrc-in-other-scripts) look like better dups. – Gordon Davisson Apr 24 '21 at 18:08
  • Even if you do enable them, you still need to source in the file where they're defined, as dotfiles aren't read by default for noninteractive scripts. Whereas with a function one can export it... – Charles Duffy Apr 25 '21 at 19:34

0 Answers0