2

I rarely touch shell scripts, we have another department who write them, so I have an understanding of writing them but no experience. However they all appear rather useless with my issue.

I am trying to execute some KornShell (ksh) scripts on a windows based machine using Cygwin- we use these to launch our Oracle WebLogic servers, now it simply will not execute. I used to be able to execute these exact same scripts fine on my old machine.

Now I have narrowed this down to the fact the 'magic number' or whatever it is at the start of the script where it specifies the script interpreter path:

i.e.:

#!/bin/ksh

if I change it to execute as a simple bash it works i.e:

#!/bin/sh

I went through checking the packages installed for cygwin - now the shells I installed are:

  • mksh MirdBSD KornShell
  • bash the bourne again shell
  • zsh z shell

Should I expect to see a ksh.exe in my cygwin/bin directory? there is a system file 'ksh' which I was making an assume somehow associates it with one of the other shell exes, like mksh.exe

I understand my explanation may well be naff. But that being said, any help would be very much appreciated.

Thanks.

javaPlease42
  • 4,699
  • 7
  • 36
  • 65
dapperwaterbuffalo
  • 2,672
  • 5
  • 35
  • 48
  • What exactly does "simply won't execute" mean? Do you get an error message? – Keith Thompson Dec 10 '13 at 00:16
  • The _magic number_ is just the `#!`, because it is a 16-bit number. I don't know the name of your Korn shell; perhaps it is `mksh`. What does `mksh --version` tell you? – user1934428 Aug 28 '23 at 13:21
  • According to [this](https://www.unix.com/unix-for-beginners-questions-and-answers/282194-need-ksh-cygwin.html), Cygwin should offer pdksh. Can you install this? And is ia suitable Korn Shell version for you? – user1934428 Aug 28 '23 at 13:23

5 Answers5

2

I believe the MirBSD korn shell is called mksh. You can verify this and look for the correct path by typing

% which mksh
% which ksh

or if you have no which,

% type -p mksh
% type -p ksh

or if that fails too, check /etc/shells which should list all valid shells on a system:

% grep ksh /etc/shells

You need to put the full path after the #! line. It will probably be /bin/mksh, so your line needs to look like:

#!/bin/mksh
Daniel Roethlisberger
  • 6,958
  • 2
  • 41
  • 59
2

You've probably fixed it by now, but the answer was no, your Cygwin does not (yet) know about ksh.

I solved this problem by launching the cygwin setup in command-line mode with the -P ksh attribute (as described in http://www.ehow.com/how_8611406_install-ksh-cygwin.html).

Asurya
  • 21
  • 2
0

You can run a ksh using a bat file

C:\cygwin\bin\dos2unix kshfilename.ksh

C:\cygwin\bin\bash kshfilename.ksh

Running a shell script through Cygwin on Windows

Community
  • 1
  • 1
0

Install KornShell (ksh) into Cygwin by the following process:

  1. Download: ksh.2012-08-06.cygwin.i386.gz
  2. Install ksh via Cygwin setup.
    1. Execture Cygwin setup.exe
    2. Choose: Install from Local Directory
    3. Select the ksh.2012-08-06.cygwin.i386.gz as the Local Package Directory. enter image description here
    4. Complete Cygwin setup.
  3. Restart Cygwin.
javaPlease42
  • 4,699
  • 7
  • 36
  • 65
0

I realize this is very delayed, but in case others have the same problem I was having, I used the same process described by Asurya, with a few additional clarifications/tips I got through trial and error:

  1. Install cygwin
  2. Open Windows PowerShell
  3. Navigate to the install location of Cygwin (for me was C:\cygwin64)
  4. Run the Cygwin setup exe with the additional flag "-P ksh" (I ran: setup-x86_64.exe -P ksh).
  5. You can also do a single-user install (no admin permission required) by appending --no-admin to that call: setup-x86_64.exe -P ksh --no-admin
  6. Run your code from within Cygwin by using the syntax (without quotes): "mksh filename.ksh" or "ksh filename.ksh" - these are equivalent, since the ksh system file simply links to the mksh.exe file in the bin folder.
  7. Rather than the above syntax, you can also ensure the proper shebang line is at the top of your file (e.g., #!/bin/ksh) and run the code by simply calling (no quotes) "./filename.ksh".

Extra notes / things I found helpful:

  • You can also activate the ksh sub-shell by typing (no quotes) "ksh" or "mksh" into Cygwin, but the syntax remains the same. Exit by typing (no quotes) "exit".
  • You can change to a directory within C:\ by using the command (no quotes) "cd /cygdrive/c/rest_of_directory" (source)
  • You can add debug functionality by using Linux "set" commands within your .ksh file. I added (no quotes) "set -x" as the new first line of my file, which then prints each command argument during execution. Particularly helpful for more enigmatic errors like "path/file2[1] is not an identifier", which I had when executing additional files/scripts from within my original script.
John R
  • 1
  • 1