0
votes

I am having a bash script that is executing another bash script:

ex:

script name "rotator" is calling script name "s3-get" like below

!# /bin/bash
...
./s3-get {and params here}

All commands as "cat", "basename" etc. run correctly here

Within the "s3-get" script there is code as:

!# /bin/bash
cat > /dev/null << EndOfLicense
...
readonly weAreKnownAs="$(basename $0)"
...
main "$@"

So, if I simply execute the s3-get script directly from shell, it runs perfectly. When I try to execute it from "rotator" script, I get the error "cat: command not found". I can fix this by changing "cat" with "/bin/cat" just that I don't think this is correct since, as I stated above, the script runs correctly when executed as standalone. If I fix the "cat" command as above, the next error that raises is "basename: command not found", then "main: command not found"

I am pretty new to shell programming, so any help is appreciated.

Thank you

1
It sounds like one of your shell scripts is modifying the PATH variable, which is how the shell finds commands when you don't give it a fully qualified command name like /bin/cat. - larsks
I would hope both scripts begin with "#!/bin/bash" not "!# /bin/bash" i.e. first hash then bang and no spaces. - Mark Setchell
You can always add "echo $PATH" at any point in the scripts to see what the PATH is set to. You can also type that command into your terminal and see what your path is normally set to outside of any scripts and then set it the same inside the scripts as the second line. - Mark Setchell
@mklement0 Maybe, but unusual, and anyway "!#" is definitely wrong. - Mark Setchell
@MarkSetchell Good point re the OP getting the shebang wrong (!# rather than the correct #!), but spaces after the #! are OK, although unusual - "rather, blanks after the shebang have traditionally been allowed" (en.wikipedia.org/wiki/Shebang_(Unix)) - mklement0

1 Answers

0
votes

Try $ echo 'export PATH=$PATH:/root/scripts/RotateVideos' >> ~/.bashrc && source ~/.bashrc in the command line and then just call it using s3-get in your script. Alternatively use cd /root/scripts/RotateVideos && bash s3-get.