1

We are running containers on open shift platform. The application pods are running fine. We able to login to the pod using the below command

oc exec -it <podname> -- /bin/bash

also tried /bin/sh

once login we are trying to execute a script which is available in a particular folder (/opt/scripts)

When we run sh script it works. When we run script without sh it throws command not found

Inside the script we have #!bin/ksh (tried with bash and also sh)

How can I run the script without sh prefix

Update: Tried to simulate the scenario inside the container

Below are the installed shells inside the container

sh-4.4$ cat /etc/shells 
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash

This is a script. The first line is updated

sh-4.4$ more tRun
#!/bin/sh

Runs only with prefix sh or bash

sh-4.4$ tRun
sh: tRun: command not found

sh-4.4$ sh tRun
JAVA_HOME is not set. Unexpected results may occur.
Set JAVA_HOME to the directory of your local JDK to avoid this message.
Please enter aguments:
^C

sh-4.4$ bash tRun
JAVA_HOME is not set. Unexpected results may occur.
Set JAVA_HOME to the directory of your local JDK to avoid this message.
Please enter aguments:
^C
Malaiselvan
  • 207
  • 2
  • 5
  • That `#!bin/ksh` should likely be `#! /bin/ksh -` (the missing `/` is the most important missing part) or `#! /bin/bash -` or `#! /bin/sh -` if `/bin/ksh` doesn't exist in that container but `/bin/bash` or `/bin/sh` does and the script doesn't use Korn-specific extensions not also found in bash/sh – Stéphane Chazelas Jun 27 '23 at 19:23
  • Please don't post screenshots of text. Copy the text here and use code formatting instead – muru Jun 28 '23 at 04:20
  • 1
    screenshot replaced with text – Malaiselvan Jun 28 '23 at 04:28

1 Answers1

2

To run “on its own”, your script needs the command given in its shebang to be available. Since that’s /bin/ksh, it needs ksh to be installed in your container image.

If your script actually works correctly with sh, you can instead change its shebang to #!/bin/sh (or better still, #!/bin/sh -).

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164