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.

learn more… | top users | synonyms

1
vote
1answer
1k views

Do shells support recursion?

I'm trying to write recursive functions in my shell scripts. Consider the following code: function printA { if [[ "$1" = 0 ]]; then return else echo "a$(printA $(("$1" - 1)))" ...
2
votes
1answer
493 views

Which version of unix from a shell?

I recently started a new job, and was told that I need to log on (Via shell) to a particular unix system. I'm trying to figure out a few peculiarities with the system, but first I need to know what ...
2
votes
1answer
591 views

Time validation with regex

I'd like to make validation about time stamp of one of my log file. But it seems I have problem on my expression in case statement. TIME value might be something like 11:49 or 2011. And I just want ...
1
vote
1answer
675 views

How to capitalize word (i.e. first letter to upper) in KornShell

Is there a builtin way in KornShell to capitalize a word, e.g. korn -> Korn? A Bash 4 example to clarify: str='korn' echo "${str^}" If there is not a bultin way to do this in KornShell, what is the ...
7
votes
1answer
2k views

Korn Shell: End, pgup, pgdown, and delete key not working

So basically my End, Pageup/Pagedown, and Delete key are not working in ksh93. I'm running FreeBSD by the way. My arrow keys are working, and so is my home key. Those keys work when I put this in my ...
5
votes
2answers
4k views

Colored Prompt in KornShell

According to this StackOverflow post, it is possible have a colored prompt in KornShell. I have not been able to figure out how to do this. I am able to use color: echo -e "\033[34mLinux\033[00m" ...
6
votes
1answer
380 views

Ksh features incorporated into Zsh?

I have been a user of Bash for some time. I want to learn at least one other shell now, so I have been picking up the Korn Shell. However, it doesn't look like Ksh has had major updates for almost ...
11
votes
7answers
688 views

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 ...
5
votes
4answers
4k views

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 ...
5
votes
2answers
3k views

What is the most correct way to pass an array to a function?

Consider I have a very large array $large_list, is there a way to write a function that will take the array as an argument? For example: echo_idx_array () { arr="$1" idx="$2" echo ...
3
votes
5answers
2k views

Formatting the output: Underlining

I wrote the following function in ksh that prints its first argument to the screen and underlines it with the appropriate ammount of - character: print_underlined () { word=$1 echo $word ...
3
votes
2answers
580 views

pure shell complex substitution in variable

However it may be impossible, I hope I'm just bad man reader =) Is there any way to substitute text in variables on several patterns at time or even using back reference? For example, I have ...
2
votes
1answer
405 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
2
votes
2answers
664 views

How to get green/red terminals under OpenBSD?

For linux machines I can use: # vi ~/.bashrc # red/green terminal colors regarding exit code export PROMPT_COMMAND='PS1="` if [[ \$? = "0" ]]; then echo "\\[\\033[0;32m\\]"; else echo ...
2
votes
1answer
110 views

When is using ~+ useful?

As I understand it, ~+ means the same thing as "the current working directory". So echo ~+ should print the same as pwd. What is the purpose of this tilde expansion ~+ ?
3
votes
2answers
326 views

issues with GNU tail -f and combination of commands

$ tail -f /logs/filename.log | awk '!(/list)' I am able to run this command in GNU Linux flavour But when I written in a script it is not working. test.ksh: variable="/logs/filename.log | awk ...
20
votes
2answers
743 views

Why escape trivial characters in shell script?

I just opened a legacy shell script (written in old ksh88 on Solaris) and found the following repeated all throughout the code: [ -f $myfile ] && \rm -f $myfile The escaping backslash ...
4
votes
3answers
4k views

How to get subshell's PID in Korn Shell (equivalent of $BASHPID)

In bash you have this handy variable: $BASHPID wich always returns the currently running subshell's PID. How can I get a subshell's PID in ksh? For example see the code below: #!/usr/bin/ksh93 echo ...
3
votes
2answers
2k views

Creating a variable with sed in ksh

I'm using Ksh88 on a Solaris 10 machine. If I do the following: foo="one two three" for i in $foo; do echo $i; done The script executes as expected: $ ./script.ksh one two three However if ...
6
votes
1answer
639 views

Why does a=0; let a++ return exit code 1?

Try it: $ a=0 $ let a++ $ echo $? 1 # Did the world just go mad? $ echo $a 1 # Yes, it did. $ let a++ $ echo $? 0 # We have normality. $ echo $a 2 Contrast with this: $ b=0 $ let b+=1 $ echo $? 0 ...
27
votes
3answers
5k views

using single or double bracket - bash

I'm confused with using single or double bracket. look at code: dir="/home/mazimi/VirtualBox VMs" if [[ -d ${dir} ]]; then echo "yep" fi It works perfectly although the string contains space. ...
1
vote
2answers
295 views

$2 (field reference) in awk BEGIN is not working

In the following snippet, $2 in awk is returning empty. What am I doing wrong? I am trying to find the difference between MAX and MIN. #!/bin/ksh if [ $# -ne 1 ]; then echo "Usage: sh ...
4
votes
2answers
31k views

pdksh missing from RHEL 6 and CentOS 6?

The package pdksh does not exist on RHEL 6 or CentOS 6 when I try to install it through yum. So my questions: Why is it no longer available in the default repositories? It is available in version ...
3
votes
3answers
2k views

How do I run a script n times at same time and how do I simulate a semaphore?

I have a text file, inside of this file is a number, and I have a script.sh in ksh. The script reads the file and gets the number, then increases the number by 1 and overwrites the new number in the ...
3
votes
1answer
1k views

Unset Read Only Variables

Is it possible to unset or change a readonly variable in Korn Shell? I am using AIX 5.
0
votes
1answer
66 views

what does “serial=${serial##*.}” do? [duplicate]

Possible Duplicate: How do ${0##/} and ${0%/} work? 0:root@SERVER:/ # 0:root@SERVER:/ # serial=$(lscfg -vl hdisk1 | awk '/Serial Number/') 0:root@SERVER:/ # echo $serial ...
5
votes
6answers
672 views

Last command in ksh

In bash I can use !! to indicate the last command. In ksh I think you can use r to do something similar, but it seems to fail in one of my common patterns: typing sudo [last command]. > cp foo ...
6
votes
5answers
1k views

How to avoid a useless use of cat when parsing a file?

I have a file containing a list of directories. For instance /foo/bar/dir1 /foo/bar/dir2 /foo/bar/dir3 I want to create all these directories. Here's what I did: for dir in $(cat myfile); do ...
1
vote
2answers
1k views

put tab before every output line on AIX/ksh

0:root@SERVER:/root # echo "something" | sed -e 's/^/\t/g' tsomething 0:root@SERVER:/root # AIX/ksh .. why doesn't it works? I just want to put a "tab" before every line!
2
votes
1answer
1k views

Multiline PS1 prompt

Is the a way to specify a multi line prompt in Korn shell? I am planning to swhitch from bash to ksh. In bash I have a very simplistic prompt, but it is 2 line prompt. I hate when input position ...
5
votes
2answers
4k views

How to get a clean environment in a ksh shell?

I need to get rid of all the environment variables in a Ksh shell. I can fork a new instance, but it will inevitably source some init files (as far as I know .profile, .kshrc). Is there a way to ...
3
votes
3answers
3k views

What are the significant differences between different shells? [duplicate]

Possible Duplicate: What are the fundamental differences between the mainstream *NIX shells? If I write a shell script in bash, will it run in ksh as well? if not, what are the ...
1
vote
3answers
306 views

ksh cannot cp from location with space in it?

I am trying to do the following in ksh but keep getting cannot stat message for the cp command: JMX_ROOT=/bfs-build/build-info/mep_mainline-Linux.latest/core/mainline/automation ...
1
vote
1answer
994 views

Concatenate multiple strings with spaces in them?

I am trying to do the following in ksh shell: JMX_ROOT=/bfs-build/build-info/mep_mainline-Linux.latest/core/mainline/automation SMOKE_JMX_LOCATION="$JMX_ROOT/\"Smoke Set\"/*.txt $JMX_ROOT/\"Smoke ...
4
votes
5answers
8k views

Match regex in ksh

I am looking to do something like this in KSH: if (( $var = (foo|bar)[0-9]*$ )); then print "variable matched regex" fi Is it possible at all? For the record I'm using Ksh Version M-11/16/88i ...
12
votes
3answers
6k views

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 . ...
1
vote
1answer
475 views

How to call a generic function without importing its file?

Assume I have a function.ksh file that contains a function called getServerIp. I don't want to create a new script file and import function.ksh, I just want to run getServerIp from my current shell. ...
1
vote
0answers
511 views

Dynamic search and replace in Ksh

Machines at work follow a constant naming pattern: host[domain]_[id] where [domain] is either "d" for dev machines and "p" for production machines, and [id] is a 2-digit string that is different for ...
5
votes
4answers
5k views

Is there a way to sum up the size of files listed?

This is the command I am using to list some files: find . -name \*.extract.sys -size +1000000c -exec ls -lrt {} \; -rw-r--r-- 1 qa1wrk15 test 1265190 Sep 29 01:14 ...
6
votes
5answers
797 views

Shell programming, avoiding tempfiles

I often write KSH shell scripts that follow the same pattern: (1) retrieve output from one or more command (2) format it using grep|cut|awk|sed and print it to the screen or to a file In order to ...
1
vote
1answer
201 views

How to replace the original value of variable in HTML tag

I am facing some problems in replacing the value of a variable in a html tag in a unix box. Here are the details. Please help me in finding a solution. #!/bin/ksh count=5 ...
3
votes
2answers
174 views

Execute command on shared account login

At work our team uses a shared account "appadmin" to administer our application. At login, each one of us sources an "aliasrc" file containing his or her preferences. (aliases, display, prompt, ...). ...
4
votes
6answers
413 views

What should I do with a remote AIX machine if I accidentally “chmod 644”-ed the “/usr/bin/ksh”?

Now the machine asks for password...The ssh was configured with key auth.. The problem is that ksh doesn't has executable permission anymore.. :\ What can I do remotely? Any tips? The root's shell ...
3
votes
2answers
4k views

Replace all occurrences of a character in a variable using korn script

Part of the Korn script I am writing requires that I replace all occurrences of the ' character with two occurrences (''). I am trying to log some SQL that I am generating in this script to a column ...
2
votes
3answers
645 views

regexp in ksh for extensions tgz, tar.tgz

I'm trying to get a regexp (in ksh) to identify files with only the following extensions: tgz, tar.gz, TGZ and TAR.GZ. I tried several but can't get them to work. I'm using this regexp to select only ...
3
votes
3answers
2k views

Get the number of files that match a pattern in a directory and delete the oldest one

I'd like to do the following: Get the number of files in a given directory that match a given pattern, for example: ExtractBackup_{date}.tar.gz If that number is 2 or higher, delete the oldest file ...
7
votes
1answer
518 views

Poor Man's GNU Parallel implemented in ksh?

I'd like to use the feature of GNU parallel where it can execute the command and the list it's fed in parallel and spit it out after it's all done, however, I don't want to install GNU parallel across ...
2
votes
1answer
477 views

Tutorial about key maping in KSH in EMACS mode

Are there any good tutorial to learn about Key Maping in Korn Shell (AIX) in EMACS mode ?
2
votes
2answers
688 views

Create a new file by removing the new line character at the end of file

I have a flat file which contains the following data records between H: and T:. H:20050427 HEADER RECORD 0000000 00000 000000000 123456 00 654321 DATARECORD 0000000 00000 000000000 123456 00 654321 ...
14
votes
2answers
758 views

How can one time out a root shell after a certain period of time?

Is there a way to 'time out' a root shell (for example, in gnome-terminal) so that after a certain amount of time not issuing any commands, the shell exits? I'm searching for a solution that works in ...