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.

816 questions
6
votes
3 answers

convert file to utf-8 based on the file command

Have an upload process, reads the file and using sqlldr it uploads the data to DB. I was getting invalid number issue while processing the file in sqlldr. Found the file is in UTF-16 format and then converted to UTF-8 format in notepad++, it started…
Pat
  • 239
4
votes
1 answer

ksh variable substitution format?

I have variables named var1EMI, var2EMI, var1DDE, var2DDE, etc and I need to be able to iterate over them like this; for dir in var1 var2 do echo "EMI value for " $dir " is " ${${dir}EMI} echo "DDE value for " $dir " is " ${${dir}DDE} done I…
4
votes
1 answer

Trapping dot (.) file not found errors in KSH

In ksh88, I can source a file using the "dot" command, like . /my/file/source.ksh However, if source.ksh doesn't exist, I want to trap the error. So I tried this: #!/bin/ksh trap "echo 'Source Not Found'; exit 1" ERR . test2.ksh But the trap…
N West
  • 143
3
votes
1 answer

Issue passing parameters to /bin/sh -c

I am trying to use /bin/sh -c to execute a .sh script with a date parameter. The -c option is not optional as it's what the framework my team has uses. I can't get the date epoch parameter to pass to my script properly. The following is an…
3
votes
1 answer

Using directive and namespace aliasing with Ksh

Can I create an alias for a korn shell namespace? Is there anything like the using directive in C++ (bring several namespaces together and throw a (compiler) error if a symbol designation is ambiguous)?
Petr Skocik
  • 28,816
3
votes
1 answer

Does ksh88 interpret a number as decimal using 10#n syntax?

I would like to treat a number with leading zero as a decimal with the least effort so I intend to use the following syntax: x=08 y=$(( 10#$x - 1 )) Will the following syntax work on ksh88?
xuesheng
  • 133
2
votes
1 answer

Does ksh93 support +o type options with its getopts(1) builtin?

ksh93 supports long options the same way as introduced by Sun Microsystems in Spring 2004 for getopt(3), Bourne Shell and ksh88. You may e.g. use: getopt(argc, argv, "V(version)"); to establish a long --version alias to the short option -V. However…
schily
  • 19,173
2
votes
2 answers

Record going to next line in a PIPE separated file

I have a pipe separated file with the format something like below 1|ABC|11|DEF|111 2|ABC|22|PQR ST UW|222 3|ABC|33|XYZ|333 4|ABC|44|LMN|444 Now for the line starting with 2 when I try to insert this record into the table the record is inserted only…
3DM
  • 21
2
votes
2 answers

ksh if statement syntax

I have this if statement and every time I change something another thing seems to be wrong. Can you see the problem? if [[ $(ps -ef | grep "Process" | grep -v "grep" | awk '{print $2}') = '' ]]; then echo "bien" fi I get launcher.sh[74]:…
lucia
  • 83
2
votes
2 answers

KSH while loop causing issues

Hi guys I'm getting this error message when running my KSH script: ./file.sh: line 16: syntax error at line 22: `done' unexpected My code is as follows: #!/bin/ksh # count=$# #count is assigned num of parameters num=$1 #assign…
lecardo
  • 143
1
vote
2 answers

viewing variable values in a KSH script

I am using a KSH script that creates numerous variables from fairly complex code. What command can I place in the script to view the value of these variables as they are created? Would ECHO be the correct command, in a line like echo variable is…
1
vote
2 answers

ksh :To store the output of a awk command in an array

I've the following awk command: awk -F ' ' '{ print $NF }' log filename And it gives the output as below: 06:00:00 parameters: SDS (2) no no no no doc=4000000000). information: 0 5898 5898 06:06:25 The problem is I need to save this in an…
Ram
  • 383
1
vote
1 answer

Confused why pgrep can't show children of jobs started in subshell

I need to use korn shell for a script I'm writing and ran into issues managing nested child processes. The example code below demonstrates my issue. In it I create a temporary file for x seconds, then remove it so I can see if the job is still…
guest
  • 77
1
vote
0 answers

Extract full function definitions

Given: $ cat test.ksh doit() { doi1() { echo doi1 "$@" } doi2() { echo doi2 "$@" } doi1 a doi2 b } doit functions doit typeset -f doit Why do I get this output (doi2() and the last } are missing): $ perl -e…
Ole Tange
  • 35,514
1
vote
1 answer

Return long integer value from a function in ksh

I use the below function in ksh to return the long value of date parts function convert_date_to_long { long_date="${1}${2}${3}" return $long_date; } but the result i get is 209 when i pass the parameters 2015 02 25 . How do i get the long…
xGen
  • 653
1
2 3