1

I have script with #!/bin/ksh in the first line. When I try to execute this script (run ./myscript.sh) the error occurred:

-bash: ./myscript.sh: /bin/ksh: bad interpreter: No such file or directory

But when I execute this script through source myscript.sh or bash myscript.sh command - script runs successfully.

Yes, ksh is not installed and it is correct to install this. But I can't understand different behavior ./ and bash or source

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Nik
  • 13

1 Answers1

5
  • When a script is executed with ./ the interpreter from the shebang line is invoked.

  • with source the current shell is used (source is a bash extension, so you have to be running bash)

  • with bash script.sh the bash shell in your PATH is invoked with the shellscript.

arved
  • 1,112