0

I have a script that runs fine when I add the "bash" in front of it,

bash ./myscript.sh /opt/config/run.config

but when I don't it stops at the below line and exits.

source "/opt/config/test.config"

No problems when I append the bash in front of the command.

Is there anything in the environment variables that I have missed as I'm setting up a new box. The same script doesn't have any issues on the older boxes.

closed as unclear what you're asking by Jeff Schaller, Rui F Ribeiro, Anthony Geoghegan, RalfFriedl, Mr Shunz Dec 18 '18 at 11:12

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 8
    Is the script executable, does it have a #!-line pointing to the correct interpreter? Do you get any error message? – Kusalananda Dec 17 '18 at 19:12
  • @Kusalananda I dont get any error message, i just stops and exits when I dont run this with bash in the front. – Jeyaprakash Dec 17 '18 at 19:21
  • 3
    Show the whole script, please. And please answer Kusalananda 's question: Do you have a shebang line (#!) and what is it? Probably, your default shell is not bash, but something that does not understand 'source' tje way bash does. – WerKater Dec 17 '18 at 19:43
2

Solution: add the shebang #!/bin/bash at the head of the script

You can force using the shell you want with the first line: #!/bin/bash which is another way of doing what you do with bash ./myscript ...

#!/bin/bash

...
...
source "/opt/config/test.config"
...
...

Possible explanation of your problem

There is no source built-in command in the shell sh (and there is no program with the name source). So if your script is run by sh, it will fail at the command line with source.

Not the answer you're looking for? Browse other questions tagged or ask your own question.