Questions tagged [ksh]

The KornShell is an open source, POSIX-compatible shell language from AT&T based upon the original Bourne shell. Make sure you know whether your ksh is ksh93 or a clone.

The KornShell was created by David Korn at AT&T. It was created at Bell Labs (then AT&T) as a logical successor to the Bourne shell as the UNIX command line interpreter and scripting language.

The KornShell is compatible in syntax with the original Bourne shell and adds several features, like an interactive command line editor, functions with local variables, and arithmetic.

History

The KornShell was originally distributed as part of the AT&T Toolchest in the early 80's.

There are many different versions of the KornShell, and it can make a difference to know what they are.

Ksh93 is currently at version [ksh93u+] (For a long time it was distributed by AT&T, now it has moved to GitHub https://github.com/att/ast) and distributed under the Eclipse Public License as part of the AST (AT&T Software Tools) project staffed by David Korn and Glenn Fowler.

  • Ksh93 precursor ksh88 was the last official version of the KornShell in the AT&T Toolchest.
  • Mortice Kern Systems ported ksh88 to DOS/Windows, and adopted by Microsoft into its UNIX toolsuite for windows. Microsoft eventually shifted to Interix for its UNIX toolsuite.
  • UNIX vendors incorporated ksh88 into their product and enhanced it (Sun Microsystems added internationalisation).
  • pdksh was distributed for UNIX (like) systems, but missed some features of the original.
  • mksh is the contemporary successor of pdksh; David Korn agreed it’s a good thing as long as it cannot be confused with the original ksh, so please add the tag for questions related to it (it’s on-topic in most ksh-related places)
  • ksh93 has been under development by the AST team since its inception, with roughly 1 major update per year. For a long time ksh93 was only available commercially, but eventually was open-sourced.

Features

The following list includes features of ksh88 and ksh93

  • command line editing - vi or emacs mode
  • command line history - use vi/emacs/arrow keys to recall earlier commands

  • Functions

  • local variables in functions
  • arithmetic (( ... )) and $(( ... ))
  • floating point arithmetic (since ksh93)
  • builtin replacements for many standard unix commands

Standardization

The KornShell (ksh93) was at the basis of the POSIX sh standard, although not all ksh93 features are included, and some posix shell features are optional.

2730 questions
28
votes
9 answers

Shell script templates

What would be your suggestions for a good bash/ksh script template to use as a standard for all newly created scripts? I usually start (after the #! line) with a commented-out header with a filename, synopsis, usage, return values, author(s),…
webwesen
  • 1,242
  • 4
  • 17
  • 30
26
votes
3 answers

redirect command output into variable and standard output in ksh

I have some shell command. I would like to write the output to the standard output and save it into variable as well. I'd like to solve it with one command. I have tried these things. ls > $VAR # redirects the output to file which name is…
Attila Zobolyak
  • 739
  • 2
  • 10
  • 15
26
votes
3 answers

Convert a text string in bash to array

How do i convert a string like this in BASH to an array in bash! I have a string str which contains "title1 title2 title3 title4 title5" (space seperated titles) I want the str to modified to an array which will store each title in each index.
Ayush Mishra
  • 1,583
  • 3
  • 13
  • 13
24
votes
4 answers

set -e and short tests

When I was new to shell scripting, I used a lot of short tests instead of if statements, like false && true. Then later I learned using set -e, and found my scripts were dying for some reason, and they would work if I replaced the short tests with…
admirabilis
  • 2,290
  • 2
  • 18
  • 33
24
votes
6 answers

Return value from a Java code

There is a Java class which creates a POST request and sends it to a servlet. The main method of the class file (test) looks something like this: public static void main(String[] args) throws IOException { // Code logic goes here... // No return…
Monojeet
  • 551
  • 3
  • 6
  • 7
24
votes
3 answers

how to get day of the year in shell?

How can I get the day of the year in shell? date '+%V' will give me the week of the year, which is 15 for today; but I need to find the day of the year!
Reza Toghraee
  • 1,603
  • 1
  • 14
  • 21
23
votes
5 answers

Why does `if $(true) ; then ... fi` succeed?

Inspired by this question: What should an if statement do when the condition is a command substitution where the command produces no output? NOTE: The example is if $(true); then ..., not if true ; then ... For example, given: if $(true) ; then echo…
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
23
votes
7 answers

Unix cp argument list too long

I am using AIX. When I try to copy all the file in a folder to another folder with the following command: cp ./00012524/*.PDF ./dummy01 The shell complains: ksh: /usr/bin/cp: 0403-027 The parameter list is too long. How to deal with it? My folder…
lamwaiman1988
  • 3,729
  • 15
  • 55
  • 87
22
votes
12 answers

Can I get the absolute path to the current script in KornShell?

Is it possible to find out the full path to the script that is currently executing in KornShell (ksh)? i.e. if my script is in /opt/scripts/myscript.ksh, can I programmatically inside that script discover /opt/scripts/myscript.ksh ? Thanks,
brabster
  • 42,504
  • 27
  • 146
  • 186
20
votes
1 answer

ORA-01741: illegal zero-length identifier

Hi I am using a delete query in my shell script and I am facing this issue. delete from WHITELIST_CLI where filecode like'%Line_Index_condense%'; Error: ERROR: ORA-01741: illegal zero-length identifier
Purple
  • 301
  • 1
  • 2
  • 6
20
votes
10 answers

changing to parent directory in unix

in general we use cd .. for going to the parent directory cd ../../ to go to the parents parent directory. and cd ../../../../../ for 5th parent directory. is there any simplified way of doing this? shell i am using is ksh.
Vijay
  • 65,327
  • 90
  • 227
  • 319
20
votes
2 answers

Reading file line by line (with space) in Unix Shell scripting - Issue

I want to read a file line by line in Unix shell scripting. Line can contain leading and trailing spaces and i want to read those spaces also in the line. I tried with "while read line" but read command is removing space characters from line…
Sourabh Saxena
  • 211
  • 1
  • 2
  • 5
20
votes
5 answers

Make Arrow and delete keys work in KornShell command line

I am new to Unix and am using sun solaris (v10 I think). I have my shell set as KornShell (ksh). I am wondering how to make the arrow keys and delete key work in the command line. I have done set -o emacs and the backspace works, but not the arrow…
user66854
  • 865
  • 3
  • 11
  • 15
19
votes
5 answers

How do you use ssh in a shell script?

When I try to use an ssh command in a shell script, the command just sits there. Do you have an example of how to use ssh in a shell script?
Jon 'links in bio' Ericson
  • 20,880
  • 12
  • 98
  • 148
19
votes
2 answers

Difference between korn and bash shell

I am completely new to Unix. Presently, I have been asked to learn about both KornShell (ksh) and Bash shell. Can some one please give me a short overview about the two? Is the term "shell" synonymous to "terminal"? I understand that I can read…
Programmer
  • 6,565
  • 25
  • 78
  • 125