Questions tagged [ksh]

The Korn shell (ksh) is a shell with advanced scripting features, commonly found on commercial unices and some BSD systems but rarely used on Linux.

The Korn shell (ksh) is a shell originally written at AT&T, with more advanced programming features than the then-existing Bourne and C shells, and a syntax compatible with the Bourne shell. Many programming features in and mimic ksh's. Several versions of ksh exist, including:

  • ksh88, the original, which was always proprietary software.
  • pdksh (public domain ksh), a free clone of ksh88 (with a few incompatibilities). Not developed since 1999; superseded by…
  • (MirBSD Korn Shell), an actively developed descendant of pdksh.
  • ksh93, a major new version of the original Korn shell, superseding ksh88; initially proprietary, then released as free software.

Further resources are available on the #ksh on Freenode channel homepage collection.

808 questions
200
votes
9 answers

Split string by delimiter and get N-th element

I have a string: one_two_three_four_five I need to save in a variable A value two and in variable B value fourfrom the above string I am using ksh.
Alex
  • 2,255
  • 3
  • 17
  • 12
170
votes
11 answers

Delete First line of a file

How can I delete the first line of a file and keep the changes? I tried this but it erases the whole content of the file. $sed 1d file.txt > file.txt
kickass13
  • 1,773
  • 3
  • 12
  • 5
143
votes
11 answers

What is the difference between $* and $@?

Consider the following code: foo () { echo $* } bar () { echo $@ } foo 1 2 3 4 bar 1 2 3 4 It outputs: 1 2 3 4 1 2 3 4 I am using Ksh88, but I am interested in other common shells as well. If you happen to know any particularity for…
rahmu
  • 19,673
  • 28
  • 87
  • 128
123
votes
4 answers

Why does parameter expansion with spaces without quotes work inside double brackets "[[" but not inside single brackets "["?

I'm confused with using single or double brackets. Look at this code: dir="/home/mazimi/VirtualBox VMs" if [[ -d ${dir} ]]; then echo "yep" fi It works perfectly although the string contains a space. But when I change it to single…
Majid Azimi
  • 3,018
  • 6
  • 31
  • 37
113
votes
4 answers

How do you use the command coproc in various shells?

Can someone provide a couple of examples on how to use coproc?
slm
  • 363,520
  • 117
  • 767
  • 871
82
votes
6 answers

Getting size with du of files only

How can I get the size of all files and all files in its subdirectories using the du command. I am trying the following command to get the size of all files (and files in subdirectories) find . -type f | du -a But this prints out the folder sizes as…
Shardul Upadhyay
  • 923
  • 1
  • 6
  • 5
79
votes
15 answers

How to color diff output?

I wanted to format the Unix files conditionally, I am currently working on diff command and wanted to know if it is possible to format the text of the diff command output. Example: Matched values should be displayed in green. Unmatched values…
Aman
  • 1,151
  • 2
  • 11
  • 17
69
votes
4 answers

Exporting a variable with dot (.) in it

How to export a variable which has dot in it. I get 'invalid variable name' when I tried : export my.home=/tmp/someDir -ksh: my.home=/tmp/someDir: invalid variable name Even escaping metacharacter dot (.) din't helped either $ export…
user1587504
  • 930
  • 1
  • 6
  • 8
61
votes
4 answers

Is the shell ksh93 dead?

On 2013-01-10 Glenn Fowler posted this to the ast-users mailing list: As has been pointed out several times on the AST and UWIN lists, AT&T gives very little support to OpenSouce software, which is why we have so few people involved with our rather…
mikeserv
  • 57,448
  • 9
  • 113
  • 229
59
votes
7 answers

When do you use brace expansion?

I understand what brace expansion is, but I don't know how best to use it. When do you use it? Please teach me some convenient and remarkable examples if you have your own tip.
Benjamin
  • 1,505
  • 2
  • 18
  • 25
51
votes
1 answer

How to get the current date and time in YYYYMMDDHHMMSS format in ksh88?

My requirement is to get difference of 2 timestamps in hours. As the date diff option is taking long for me to figure out I am trying to convert both dates in to YYYYMMDDHHMMSS format and find the number difference. So I need to get the current date…
xGen
  • 643
  • 1
  • 7
  • 8
47
votes
2 answers

What does this ${@:2} mean in shell scripting

I see this in a shell script. variable=${@:2} What is it doing?
Raj
  • 643
  • 2
  • 8
  • 11
45
votes
4 answers

Use a variable reference "inside" another variable

I'm sure it is relatively simple, I just don't know how to do it. #!/usr/bin/ksh set `iostat` myvar=6 I want to something like echo ${$myvar} which i want interpreted as ${$myvar} -> ${6} -> value
Brandon Kreisel
  • 1,058
  • 2
  • 11
  • 14
44
votes
4 answers

Executing user defined function in a find -exec call

I'm on Solaris 10 and I have tested the following with ksh (88), bash (3.00) and zsh (4.2.1). The following code doesn't yield any result: function foo { echo "Hello World" } find somedir -exec foo \; The find does match several files (as…
rahmu
  • 19,673
  • 28
  • 87
  • 128
43
votes
4 answers

Using sed to color the output from a command on solaris

I have a ksh script that must work on both linux and solaris. I'm trying to color the output of specific commands. It works on linux (specifically RHEL6), but not on solaris (SunOS 5.10). Command on linux (the output "test" is correctly colored…
acm
  • 533
  • 1
  • 4
  • 5
1
2 3
53 54