简体   繁体   中英

Unable to execute shell script in Cygwin as a KornShell script

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:

ie:

#!/bin/ksh

if I change it to execute as a simple bash it works ie:

#!/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.

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

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 ).

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

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 . 在此处输入图片说明
    4. Complete Cygwin setup.
  3. Restart Cygwin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM