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

4
votes
1answer
853 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 ...
0
votes
1answer
38 views

Assign hostname to a variable in ksh

I am trying to assign the output of hostname to a variable and use it in my script. While I was able to get the variable to another logic, when I try to print the variable it doesn't print the ...
2
votes
1answer
54 views

Change the key that show previous command lines in ksh

In most shells on Linux, when you press the Up-arrow key, it shows the previous command lines from the command line history. My question is, for the ksh shell, How do I set up some other key so ...
3
votes
2answers
36 views

Execute command within current shell before every prompt

I'd like to have the current jobs status displayed in the title of my terminal. In Bash, I can use PROMPT_COMMAND for that. Korn Shell (ksh93) doesn't have that. Other answers suggest using command ...
0
votes
0answers
28 views

Linux Shell Script Question. Comment out particular lines in a file [duplicate]

I have a very large file. I will put a short example below. I need to find a line containing a particular string, Then comment out that line, plus 2 lines above and 1 line below. also must maintain ...
1
vote
1answer
60 views

KSH script having trouble reading in variables line by line

For starters, I'm not the most advanced scripter. I was asked to create a script that would search through a directory for print files older than 14 days and move them to an archive directory. There ...
1
vote
1answer
39 views

How to use the setarch uname command in a shell script

I am trying to create a korn shell script in RHEL7 to silently install an agent at my job. However the agent requires an old version of the agent be installed before being upgraded to the new version ...
3
votes
2answers
52 views

Remove old files in a directory except files present in an exception file

I am writing a shell script to delete old files (older than 60 days) in a directory except few files and these file names are maintained in an exception file present in another directory. I know the ...
0
votes
1answer
46 views

Up arrow at an empty prompt in ksh93

This is a request for explanation or pointer to documentation. I'm a KornShell93 (ksh on Mac OS X or ksh93 elsewhere) user. I like the shell for its relative simplicity as an interactive shell and ...
7
votes
3answers
63k 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 5....
0
votes
0answers
30 views

Delete files based on files name comparing to sysdate? [duplicate]

I've files with a prefix name like this: 20160623a.dat 20160623b.dat 20160623c.dat 20160623d.dat [20160623] is a prefix that generated with date "+%Y%m%d" command. I'd compare this prefix to ...
7
votes
1answer
744 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 ...
10
votes
1answer
290 views

How does ksh93 avoid forks in command substitution

Given cmd='fun(){ echo "$@"; }; fun $(fun $(fun hi))' shells tend to need to make 2 forks to make it happen strace-f(){ strace -f "$@" 2>&1; }; for sh in dash bash zsh ksh; do ...
1
vote
0answers
17 views

Returning an array from a ksh93 function

I would like to return an array from a function in ksh93. At this point, using the following method, the contents of the array are passed as a single element even though, in the fonction, the array ...
0
votes
1answer
52 views

Unix, create file based on command [duplicate]

I have a command, but I want to get the results into a .txt file I can open. How do I alter my command to allow the results to be put into a text file. I plan to transfer this .txt file to my local ...
3
votes
2answers
114 views

Setting the title for Xterm with long paths

I have the following code in my .profile: case $TERM in xterm*) HOST=`hostname` PS1='^[]0;${USER}@${HOST}: ${PWD}^Gksh$ ' ;; *) PS1='ksh$ ' ;; esac ...
1
vote
1answer
46 views

Output broken when appending output of sql query in ksh

I'm very new to scripting. I would like to add the output of the sql function given below to another variable for example: month_end () { mdate=$($SQLPLUS_HOME/sqlplus.exe -S $DBC << END set ...
0
votes
1answer
22 views

AIX ksh script to define exported variables locally based on a remote file's definitions

I have to get "export" lines from a remote file on another server, then set the current sh session env dynamically. However, echo with export doesn't seem to work. echo `export CONFIGA=...
10
votes
3answers
11k 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" ...
1
vote
1answer
27 views

Extract creation date and modification time of file in Sunos [duplicate]

I want to extract creation date of a file and modification time. The format should be( yyyymmddhh24miss) My unix shell /usr/bin/ksh The file: file.txt My system: SunOS 5.10 Generic_150400-23 sun4v ...
1
vote
1answer
39 views

Automating ftp processes

My shell: bin/ksh My system: Linux 2.6.18-406.el5 #1 SMP Fri May 1 10:37:57 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux My script: ftp -divn XXX.XXX.XX0 << EOF! user user pass cd /home/dir1/...
-2
votes
2answers
213 views

Unix for loop and grep combined ksh hp-ux

What if you have 5 or 6 files, specific files .biz in a directory, and you want to store them one at the time in a variable $file, and apply a set of command until no more .biz file are found in the ...
0
votes
1answer
14 views

Create a file with the concatenated information of all files that start with “file_excel”, in chronological order

my system: Linux 2.6.18-406.el5 #1 SMP Fri May 1 10:37:57 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux my shell: /bin/ksh My issue: I want to create a file: data_excel with the information of the ...
2
votes
2answers
39 views

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 ...
0
votes
3answers
145 views

stat command not found

I want to execute stat command in my unix shell /usr/bin/ksh: Input: /bin/date +%Y%m%d%H%M%S -d "$(/usr/bin/stat -c %x find.txt)" And the output: /usr/bin/ksh: stat: not found My system: SunOS ...
3
votes
1answer
12k views

-ksh: revenue_ext.ksh: not found [No such file or directory]

I am getting the same not found [No such file or directory] error when trying to execute a ksh script. Read tips about the PATH and running the script with a ./ in the posts here and here and tried ...
0
votes
1answer
141 views

How to spawn new processes for new instances of the same shell script?

I'm trying to lock a file using the command lock. Its syntax is ./lock </path/to/file/name> I need to lock a bunch of files in a given directory and in order to achieve this I'm using two ...
48
votes
4answers
17k 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. ...
3
votes
6answers
1k views

Check in ksh if a directory is empty

How do I check if a directory is empty or not in ksh on AIX? If files exist I need to remove files only.
0
votes
1answer
47 views

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 ...
0
votes
2answers
1k views

ksh - map Ctrl-D to exit shell

I would like to know how we can map the keys Ctrl-D in ksh to exit the shell as it does in bash shell. Not much familiar with key binding in ksh. Edit See my comments below. $ echo $0 bash $ exit ...
2
votes
4answers
97 views

How to format a bash loop using sed, awk, grep, and wc

So I have a text file that I need to get extract specific lines out of and count the number of times a number in a specific column appears. I have about 100 or so of these files. I can get it done ...
0
votes
2answers
201 views

How can I redirect the same message to both stdoud and stderr (without temporary object)

It is easy to redirect stdout or stderr to the same output (file or one of the 2 std output) with a 1>&1,>&2 and/or >file. Is there a way to send the same output to both the std ...
1
vote
1answer
55 views

How to organize files in main directory into smaller amount of files in sub-directories [duplicate]

I have a directory of 150 files that I wanted split into sub-directories of 25 files each: 1-25 into dir1, 26-50 into dir2, and so on. How can I accomplish this? dir1/fre_4_g2_c3654214.h3 dir1/...
-5
votes
1answer
102 views

Exit a program by pressing the key q

I have wrote a shell script in which I would like to include the functionality to exit the program by pressing the q key. Can I do that? Here is what I currently have: #!/bin/ksh echo "Press Q to ...
0
votes
1answer
56 views

Prepare update command using sed

I have a output file that contains 3 different column data- ['AARF'],SAMPLE12,2016-01-05 12:00:00-0500 ,529OFFST,2015-04-16 08:04:21-0400 "['EPROSP_IWS', '...
0
votes
2answers
50 views

pausing a loop in AIX to wait for user input

I'm searching for a scripting mechanism that can realize the following idea. Loop over a list and stop/wait on "read x" until the next input from a user. I know the following script is not working! As ...
15
votes
4answers
11k views

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 ...
1
vote
2answers
51 views

How to benchmark different shells [closed]

I want to know if shell 1 is better for a job than shell 2 with a test that I handle maybe with shell 3 for example ksh, dash, bash or zsh. I use a test script that builds my projects, starts it,feed ...
0
votes
1answer
29 views

Checking that $((a * b)) evaluates in my own shell [closed]

POSIX seems to define that a shell should be able to evaluate like a calculator the expression $(( a * b)) where * is a binary operator +, - or *. I programmed such a calculator for my own shell and ...
1
vote
2answers
31 views

Variable assignment in a ksh script

I am viewing a ksh script and I see a function where the variable has been defined as below. Can anyone explain what exactly the below assignment of variable means in ksh script? temprule="\$${...
0
votes
3answers
52 views

sed substitution

I have a string as follows: /test/test/ 12 /test/test My goal is to turn it into: /test/est/ 12 /test/test This is the command: echo "$x" | sed 's@\(/*/\).@\1@g'" I am using at the moment but ...
9
votes
2answers
2k views

Are there problems with hyphens in functions, aliases, and executables?

In my testing (in Bash and Z Shell), I saw no problems with defining functions or aliases or executable shell scripts which have hyphens in the name, but I'm not confident that this will be okay in ...
2
votes
1answer
484 views

How to have a bash script perform a specific action on errors of _each_ command?

Similarly to set -e performs an exit on "uncaught" $? != 0, I'd like to have this event trigger the execution of another command, e.g. a logger call. How can this be done?
1
vote
2answers
383 views

su -c command fails when sending db2 commands

I have a script I've setup to run a number of tasks, one of which is to set up a table in a DB and later remove it (for automated testing). The issue comes that on only a few of the users that I use ...
-1
votes
1answer
41 views

for loop to evaluate multiple directories and execute command

I was editing a shell script and I want to know how can use for to use all directories listed by a list or variables and then execute a command. Example: I have this directories: /dirname1/app1 /...
0
votes
1answer
21 views

KSH password generator

How to make sure the generated passwords contains all these special characters: ?!/=\? Currently I'm using: pwd_usr["$i"]=`cat /dev/urandom|tr -dc "a-zA-Z0-9-_\?\!\=\/\"|fold -w 15|head -n 1` But ...
2
votes
3answers
773 views

Why can't Korn Shell do ctrl-r?

If I use PC-BSD with the default shell (Korn) then Ctrl+r doesn't work. Why won't it work? Ctrl-r was introduced to search your history in the late 1970s or early 80s and my BSD still can't do it (...
0
votes
0answers
21 views

search insert and replace [duplicate]

I want to search each record (records are defined by blank lines) in a file for the pattern NAME#AAAA. If it matches, then insert an # in front of the record's AGE line and move that line to the top ...
0
votes
0answers
16 views

I want to search for a pattern in a file. If the pattern matches, it should check for second pattern and replace it with another pattern file [duplicate]

I want to search for a pattern in a file. If the pattern matches, it should check for second pattern and replace it with another pattern INPUT FILE Name#AAAAA std 1 sec c age 5 Name#BBBB std 2 ...