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
51
votes
11 answers

Shortest command to calculate the sum of a column of output on Unix?

I'm sure there is a quick and easy way to calculate the sum of a column of values on Unix systems (using something like awk or xargs perhaps), but writing a shell script to parse the rows line by line is the only thing that comes to mind at the…
An̲̳̳drew
  • 13,375
  • 13
  • 47
  • 46
49
votes
5 answers

How to read just a single character in shell script

I want similar option like getche() in C. How can I read just a single character input from command line? Using read command can we do it?
footy
  • 5,803
  • 13
  • 48
  • 96
49
votes
8 answers

Find all files in a directory that are not directories themselves

I am looking for a way to list all the files in a directory excluding directories themselves, and the files in those sub-directories. So if I have: ./test.log ./test2.log ./directory ./directory/file2 I want a command that returns: ./test.log…
Alex
  • 6,843
  • 10
  • 52
  • 71
47
votes
3 answers

Is it necessary to specify traps other than EXIT?

I see a lot of shell scripts that do: trap cmd 0 1 2 3 13 15 # EXIT HUP INT QUIT PIPE TERM In every shell I have access to at the moment, all the traps other than 0 are redundant, and cmd will be executed upon receipt of a signal if the trap is…
William Pursell
  • 204,365
  • 48
  • 270
  • 300
47
votes
8 answers

How to set the From email address for mailx command?

I am working on a KornShell (ksh) script running on a Solaris server that will send out an email when and error condition is met. I am sending the email via mailx. Question: How do I set the "From" email address on the mailx command? Current…
AieshaDot
  • 785
  • 3
  • 7
  • 13
45
votes
17 answers

In a unix shell, how to get yesterday's date into a variable?

I've got a shell script which does the following to store the current day's date in a variable 'dt': date "+%a %d/%m/%Y" | read dt echo ${dt} How would i go about getting yesterdays date into a variable? Basically what i'm trying to achieve is to…
Chris
  • 39,719
  • 45
  • 189
  • 235
41
votes
4 answers

compare contents of two directories on remote server using unix

I am new to unix and need some help here. I have two directories present on two different server. both the directories contains the same files. Now i want to check if all files are in sync in both the directories. If files are not in sync then i…
DSD
  • 591
  • 2
  • 9
  • 19
37
votes
4 answers

Extract list of file names in a zip archive when `unzip -l`

When I do unzip -l zipfilename, I see 1295627 08-22-11 07:10 A.pdf 473980 08-22-11 07:10 B.pdf ... I only want to see the filenames. I try this unzip -l zipFilename | cut -f4 -d" " but I don't think the delimiter is just " ".
Thang Pham
  • 38,125
  • 75
  • 201
  • 285
36
votes
9 answers

How do I recursively list all directories at a location, breadth-first?

Breadth-first list is important, here. Also, limiting the depth searched would be nice. $ find . -type d /foo /foo/subfoo /foo/subfoo/subsub /foo/subfoo/subsub/subsubsub /bar /bar/subbar $ find . -type d…
Andrey Fedorov
  • 9,148
  • 20
  • 67
  • 99
35
votes
4 answers

How to add text at the end of each line in unix

I am doing certain text processing operations and finally able to get a file something like this india sudan japan france now I want to add a comment in the above file like in the final file it should be something like india | COUNTRY sudan |…
user2647888
  • 721
  • 1
  • 13
  • 22
34
votes
5 answers

Check if file exists and whether it contains a specific string

I want to check if file2.sh exists and also if a specific word, poet is part of the file. I use grep to create the variable used_var. #!/bin/ksh file_name=/home/file2.sh used_var=`grep "poet" $file_name` How can I check if…
randeepsp
  • 3,572
  • 9
  • 33
  • 40
32
votes
7 answers

Iterating through a range of ints in ksh?

How can I iterate through a simple range of ints using a for loop in ksh? For example, my script currently does this... for i in 1 2 3 4 5 6 7 do #stuff done ...but I'd like to extend the range way above 7. Is there a better syntax?
razlebe
  • 7,134
  • 6
  • 42
  • 57
29
votes
4 answers

How to export multiple variables with same value in ksh?

I want to set the following variables to the same value in one single line Example: export A=B=C=20 There is a syntax available in 'bash' but how can I accomplish the above in ksh ?
Sathish Kumar
  • 2,150
  • 10
  • 29
  • 51
29
votes
1 answer

File execution with dot space versus dot slash

I am attempting to work with an existing library of code but have encountered an issue. In short, I execute a shell script (let's call this one A) whose first act is to call another script (B). Script B is in my current directory (a requirement of…
TTT
  • 1,175
  • 2
  • 14
  • 32
29
votes
10 answers

How to expand shell variables in a text file?

Consider a ASCII text file (lets say it contains code of a non-shell scripting language): Text_File.msh: spool on to '$LOG_FILE_PATH/logfile.log'; login 'username' 'password'; .... Now if this were a shell script I could run it as $ sh…
Kent Pawar
  • 2,378
  • 2
  • 29
  • 42