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
52 views

Is there an advantage in using ksh over zsh? [closed]

Or are there any advantages for using ksh over zsh? Would any specific commands not execute successfully across the shells or are the major differences not command related, but something else?
2
votes
2answers
34 views

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

How to reset the file descriptor

I was trying to use file descriptor for printing the lines in the file #!/usr/bin/ksh exec 3<&0 exec 0< file.txt while read LINE do echo “$LINE” done and I am done with my code ,it ...
1
vote
3answers
125 views

Print the last-but-one field

How to print the word before the last word in line (with ksh or awk or sed or perl one liner) Example 1: echo one two three will print "two" Example 2: echo 1 2 3 4 5 6 will print "5"
1
vote
2answers
35 views

get arguments passed and put it in an array

is there a way to make the arguments passed become the element of an array? I want to access those arguments individually through array. like this: ./script.ksh arg1 arg2 arg3 then it will become ...
0
votes
1answer
60 views

is there a “goto” like command in ksh

Here is my script: #!/bin/ksh #this is where I want to go again if user enter #an answer other than "yes or no" echo "yes or no?" read ans case $ans in [yY]*) echo "yes" ;; ...
1
vote
4answers
282 views

awk + print awk output in one line

When I run the following hasys command with awk , I get output with machines names as the following: hasys -display|grep Shutdown | awk '{print $1}' machine1a machine1b please advice how to ...
1
vote
3answers
83 views

Korn Shell: Show elapsed time in a specific format

In a log file, I need to print the Elapsed time, in the following format: "Process completed %s - Elapsed %s", <time now in HH:MM:SS format>, <difference from start date to end date in ...
1
vote
1answer
77 views

How to get the JSON STRING from the given string

I have a string given below. I just need to get the first accountHeader (bolded) JSON string, I tried everything.. It didn't work. Can you help me to get the data? <START ...
2
votes
2answers
47 views

Replacing a pattern with another between first and second occurrence of a pattern in file

Want the comma's (,) replaced by the alphabet u between the first occurrence of y till the second occurrence of y. Given below is the sample input file. 100y00893225900,008932259,06,2013,NOKIA Q ...
0
votes
2answers
77 views

perl one liners + match word and delete string after separator

I work with linux/solaris machines and I need to add some rule in my ksh script: Please advise how to match the password word in file, and delete the value password after the separator "=" with perl ...
0
votes
1answer
51 views

perl one liners + print line if match last word but with space

The following perl syntax will print the line in case line was ended with "DUPLEX" But Sometimes DUPLEX have one space or more as "DUPLEX " so in this case line will not printed Please ...
1
vote
2answers
43 views

Is this an array?

I'm currently looking at an existing script that have something like this: variable='val1 val2 val3 val4' Is this another way of setting an array? If not, what is it?
1
vote
1answer
22 views

Count number of elements in an array

I would like to ask if there is a way to count the number of elements in an array in ksh.
1
vote
2answers
64 views

Keeping the latest two version and delete the remaining

I have a list of files (say xsl format below) in one directory. I want to keep the last two version of all files. (I can delete the remaing files) {A}_1.0.xsl {A}_2.0.xsl {A}_3.0.xsl {A}_4.1.xsl ...
1
vote
2answers
27 views

Is there an equivalent to bash's “nocaseglob” in ksh?

I would like to do what is mentioned in How to match case insensitive patterns with ls? except for ksh. Is it possible to do it without any pain(regex)?
1
vote
1answer
30 views

Problematic quotations

#!/bin/ksh typeset FILE_SIZE1=$(stat -f '%z' test.txt); typeset -r BK_STATARGS="-f '%z'" typeset FILE_SIZE2=$(stat ${BK_STATARGS} test.txt); echo without arg var ${FILE_SIZE1} echo with arg var... ...
2
votes
2answers
47 views

Help with 64-bit integers in scripts?

Maybe I'm overthinking this (although I don't think I am)....or maybe there's a neater way of solving my problem ? I have a requirement that if a file is larger than 1GB, it gets split into smaller ...
0
votes
1answer
35 views

Truncating strings after a word in unix [closed]

I have a sentence Albert Einstein was born in Ulm, in the Kingdom of Württemberg in the German Empire on 14 March 1879. I want to truncate the above sentence after kingdom and look like the ...
1
vote
1answer
55 views

Crontab Triple Redirect

I have a very basic understanding of redirects, but I have come across a cronjob with redirects which I do not understand. 00 19 * * 1-5 /apps/app/scripts/doit.sh a np cron > ...
4
votes
3answers
135 views

Sort all directories based on their size

I'd like to sort all the directories/files in a specific directory based on their size (using du -sh "name"). I need to apply this command to all directories in my location, then sort them based on ...
1
vote
3answers
89 views

Quoting in command substitution

The command pdftk FileOne.pdf "File two.pdf" output Combined.pdf works as expected, merging PDF's One and Two. However, if I put the filenames in a file FileOne.pdf "File Two.pdf" and ...
2
votes
3answers
78 views

Display what has been copied by `cp` (using `ksh`)

I'd like to get output showing what has been copied by cp. The only problem is how to do it when I cp many files at a time. For instance, cp ./sourceDir/* $destinationPath/.
0
votes
1answer
62 views

What does Grep */* mean in KSH

In ksh, what does grep */*[myPattern] mean?
2
votes
2answers
67 views

Replicate a directory and file names n times

I have folder which has some data (files) in that with the name 201311261418 And a file 201311261418.eob In my scenario I need to replicate this folder and file names n times with the appended ...
0
votes
2answers
62 views

cp all files and subdirectories in a directory ksh

How can I do a cp to copy all files including all sub-directories in the current directory. I looked at the man page, but I can't figure out how to do it.
2
votes
3answers
60 views

Change value of a strings representing number

I have the following expression : a="2013" How can I change the value of a to "2012".
1
vote
1answer
144 views

Grep pattern in ksh [duplicate]

a small question regarding grep. I'm doing : find . -type d And I have three directories : ./backup-2013-11-27 ./backup-2013-11-26 ./backup-2013-11-28 If I only want to retrieve the one from ...
0
votes
1answer
45 views

Test what cd has done ksh

I'm facing a small issue here. I'm doing : cd $(find . -type d | grep "${4:0:4}.*${4:4:2}.*${4:6:2}") $4 is a data entered from the user. However, if the user doesn't respect the format to enter, ...
0
votes
1answer
63 views

ksh if with several conditions

I'd like to know what's the syntax for this kind of if in ksh : if [[ $tmpEngine != "a" || $tmpEngine != "b" || $tmpEngine != "s" ]]; then ... fi Actually, my code doesn't work, what's the ...
0
votes
1answer
125 views

Sorting with command ls in unix (ksh) [closed]

I'm wondering how does the sort works with ls. For example: ls - lrt tri par date ls - lSr par size, ... However I don't see how this pattern works.
2
votes
1answer
153 views

KSH : cp only based on file size

I would like to write a small script copying from a directory A to directory B all the files with the .log extension. So in my directory A, I've : ls : a.log b.log c.log Here is the pseudo-code I ...
0
votes
0answers
66 views

String length limitation for user input

There is simple korn shell (bash has the same behavior) script: #!/bin/ksh read userInput I have two Solaris 9/10 servers. On one of the server i can type long string while read is running. But on ...
0
votes
1answer
37 views

KSH conventions scripting [closed]

I'm writing scripts in ksh atm. I'd like to know if there is any "conventions" as for example, always doing "unset" before using a variable, or using typeset to define a new variable, etc.
1
vote
1answer
106 views

Changing the current directory using a script (ksh)

I'm launching my script from echo $PWD ---> /x. I want my script to change my current directory. So my script contains +- this : cd /y exit 0 However, when my script ends, I'm stils in echo $PWD ...
0
votes
1answer
27 views

Using variable in KSH function

I tried to have a switch if either an option is set or not while getopts "s:u:d:e:ch" _OPTION; do case $_OPTION in ... c) isCSet="Y" then I'm ...
0
votes
1answer
98 views

Using alias in another script (ksh)

I'm writing a ksh script, and I'd like to use a command define by an alias in my .profile file, in my script. I tried this command in the folder containing my script, and it works. However, in my ...
0
votes
3answers
56 views

Ksh script warnings [closed]

While running my script, I got the following message (it's not an error strictly speaking, because the execution go ahead after) : myScript -s test -u test2 pk_copylogs[2]: hist: :: not found ...
0
votes
1answer
52 views

Function, return value using pwd in KSH

I tried to write a small ksh script: fDestExists (){ cd /tmp read vANSWER?" >> Do you want to create a repository in pwd ? Type YES or NO" echo " |----> $(fGetDatum) You ...
1
vote
1answer
65 views

How to retrieve environment variable from string name in KSH

I've the following variable : x="envVar" and 'envVar' is the one of my environment variable's name containing a path (of a folder by instance). So I'd like to do cd $x but it doesn't work. ...
1
vote
1answer
40 views

Looping through commands' results, KSH script

I'd like to put two strings in two different variables. Let's take a small example. after a simple grep, I got this : $ grep nl.*acc.*bas : ABAS01=... ABAS02=... I'd like to have two variables, ...
0
votes
1answer
50 views

How to make options mandatory in KSH script

Here is the skeleton to catch arguments in my script : # fMain(){ while getopts "d:e:h" _OPTION; do case $_OPTION in d) ...
2
votes
1answer
88 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?
8
votes
2answers
272 views

Merge three file in to a single master file by excluding the header in 2nd and 3rd files

I have three file with n number of lines as given below sample1.txt ------------------------------ Date Time Name ------------------------------ 2013/10/12 12:09:09 Krish ...
4
votes
1answer
56 views

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

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 ...
4
votes
3answers
252 views

using awk to split a line on single spaces not multiples

I'm trying to split a line that I have no control over the format of. If parameter 7 and 8 are missing which is possible they will be replaced by a space so I would end up with, field1 field2 field3 ...
1
vote
1answer
70 views

creating variable using variable value as part of new variable name

I'm trying to create a new variable using the value of an existing variable as part of the variable name. filemsg"$word1"=" " I've also tried filemsg$word1=" " filemsg${word1}=" " on all ...
0
votes
2answers
55 views

Checking if one of 4 variables starts with string &red in ksh

I'm trying to check if one of 4 variables starts with the string "&red" and I'm struggling to get the match to work. At the moment I've got this, if [[ $filemsgCICS = "&red"* || ...
1
vote
2answers
50 views

copy a section of data from stdin [closed]

I am running a script that takes its input from stdin. This input can end up being very large so I want to extract the part I'm interested in to a temp file. The first line contains "[cics]" and I ...