Running a shell script with and without “bash” command [closed]
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.
linux bash shell-script shell
closed as unclear what you're asking by Jeff Schaller, Rui F Ribeiro, Anthony Geoghegan, RalfFriedl, Mr Shunz Dec 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.
add a comment |
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.
linux bash shell-script shell
closed as unclear what you're asking by Jeff Schaller, Rui F Ribeiro, Anthony Geoghegan, RalfFriedl, Mr Shunz Dec 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 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 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 at 19:43
add a comment |
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.
linux bash shell-script shell
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.
linux bash shell-script shell
linux bash shell-script shell
asked Dec 17 at 19:10
Jeyaprakash
1063
1063
closed as unclear what you're asking by Jeff Schaller, Rui F Ribeiro, Anthony Geoghegan, RalfFriedl, Mr Shunz Dec 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.
closed as unclear what you're asking by Jeff Schaller, Rui F Ribeiro, Anthony Geoghegan, RalfFriedl, Mr Shunz Dec 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 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 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 at 19:43
add a comment |
8
Is the script executable, does it have a#!
-line pointing to the correct interpreter? Do you get any error message?
– Kusalananda
Dec 17 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 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 at 19:43
8
8
Is the script executable, does it have a
#!
-line pointing to the correct interpreter? Do you get any error message?– Kusalananda
Dec 17 at 19:12
Is the script executable, does it have a
#!
-line pointing to the correct interpreter? Do you get any error message?– Kusalananda
Dec 17 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 at 19:21
@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 at 19:21
3
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 at 19:43
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 at 19:43
add a comment |
1 Answer
1
active
oldest
votes
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
.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
.
add a comment |
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
.
add a comment |
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
.
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
.
answered Dec 17 at 20:27
sudodus
1,10616
1,10616
add a comment |
add a comment |
8
Is the script executable, does it have a
#!
-line pointing to the correct interpreter? Do you get any error message?– Kusalananda
Dec 17 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 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 at 19:43