I have a simple shell script:
#!/bin/bash
var="foo"
echo $var
When I run it, using sh shell.sh
(shell
being its filename, I get the following error:
: not found: 2: shell.sh:
What does this mean?
I have a simple shell script:
#!/bin/bash
var="foo"
echo $var
When I run it, using sh shell.sh
(shell
being its filename, I get the following error:
: not found: 2: shell.sh:
What does this mean?
Have you tried sh ./shell.sh
instead of sh shell.sh
?
(for security reasons, the current directory .
is NEVER in the PATH varable)
Also the first line in your script #!/bin/bash
is only needed if the script is run by itself,
like ./shell.sh
(don't forget to do chmod a+x shell.sh
in that case)
Finally the sh
command invokes the dash shell, not the bash shell, so it would be wise to invoke bash scripts like bash ./shell.sh
instead of sh ./shell.sh
Take care with line endings:
Bash does not accept \r\n (CRLF) as line endings (which is windows style).
Only \n (LF) is permitted.