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

ksh “<<EOF” script to change user

In the simplest form I am puzzled why this script does not work as expected as a here script changing users with su - user <<EOF. su - db2prd<<EOF PARMDATE=1111111 echo parmdate echo ...
2
votes
3answers
43 views

Calculate date difference between Last modified date of a file and NOW using shell script

I am trying to calculate the time elapsed since the log file was last updated. I guess following commands will be used lastUpdate=$(date -r myLogFile.log) now=$(date) How can I subtract them and ...
1
vote
1answer
21 views

After removing the history file, why do I still have older commands in the history?

In a ssh session every time that I open it I assign a value to a variable. Then I remove history with command rm -f .sh_history. Everything is ok but why if I have other session opened and I do an ...
-1
votes
2answers
25 views

if else statement

I have a case statement inside some of the if statement, but after doing the case statement inside the if statement, the loop ends. After the case statement, it is supposed to go to the next value on ...
-3
votes
0answers
21 views

How can I use multithreading in unix by considering its core's and cpu's? [closed]

I actually designed a unix script for automate the backup and i used multithreading concept to make multiple gtar command to run simultaneously by getting the thread value in run time. My script is ...
2
votes
1answer
27 views

Using different profiles (.kshrc_xxx) in ksh

In bash you can load a different profile by using the --rcfile option, is there such an option in ksh? Or perhaps a workaround... I know you can invoke the shell without the .kshrc profile using the ...
2
votes
3answers
187 views

How to compress the directory and its contents

How do I compress a directory and its contents in ksh on AIX for a file I do compress filename
-2
votes
1answer
42 views

Understanding of a Batch

I need your help to check if my understanding of those lines are correct. As a rookie in Unix, I work step by step. if [ $? -ne 0 ]; then I didn't find any correct explanations about the -ne but I ...
1
vote
2answers
26 views

scripting- Ignoring a variable when undefined

HP-UX *** B.11.31 U ia64 **** unlimited-user license Hello, var1=abc var2=xyz touch $var1 $var2 $var3 if the one of the variable is not set the command fails with ksh: var3: parameter not set ...
1
vote
2answers
42 views

Touch the file to future time stamp

I have created the file which is 30 minutes old by using following command TZ=ZZZ0 touch -t "$(TZ=ZZZ0:30 date +%Y%m%d%H%M.%S)" $HOME/reference Similarly how can I create a file 30 minutes of ...
2
votes
4answers
84 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
25 views

Is there a valid way of exporting a variable across different shells?

For some reasons, Im using ksh and zsh in my scripts and returning to -bash, I need to use already set variable values in the spawned shells, writing it to some temp file and using that didn't look ...
4
votes
1answer
93 views

Is there anything equivalent to getch() in ksh?

I am writing a script in Korn Shell, where at one statement I want something like getch() used in C. I want my while loop to be exited, if it sees that I have pressed ESC in Keyboard. For eg. while ...
0
votes
0answers
22 views

what is the meaning of “${x%*.*}” in shell? [duplicate]

While I am using the code as ${x%*.*} it is excluding the extension of the file. for e.g. $ x="file.txt" $ y="file.20150208.dat" $ echo "${x%\*.\*} ${y%\*.\*}" file file.20150208 But how this ...
0
votes
1answer
19 views

What is the meaning of “${name##*/}” in Shell [duplicate]

I have a code as while read name; do uuencode "$name" "${name##*/}"; done but I do not understand what is meaning of ##*/ in "${name##*/}" Google doesn't give good results. Can someone please ...
1
vote
1answer
31 views

Retrieving words before certain characters without having to use Perl

I have where clauses for SQL queries in text form, and I'd like to extract the column names from them. The clauses can contain conditions like col_1 = 'Spruce' and col_2 in ('Argentina', 'Cameroon'). ...
1
vote
3answers
67 views

Cronjob doesn't execute shell script, but when I am executing it standalone it works. Why?

Shell Type: >echo $SHELL /bin/ksh Cronjob : 15 * * * * /bin/ksh /wls_domains/resMGT/logs/bea/wlr3queuetransaction.sh > /wls_domains/resMGT/logs/bea/data/script.log The script is as below: ...
8
votes
2answers
317 views

tar to pipe but keep -v verbose output separate from STDERR

A normal tar command tar cvf foo.tar ./foo >foo.out 2>foo.err has three output IO streams archive data to foo.tar list of filenames to STDOUT (redirected into foo.out) error messages to ...
1
vote
1answer
40 views

Read from character delimted file and assign into variables | for email

I am using ksh. I need to read the data from file, into the variables and then further use them for sending emails. File can be delimited by any less used characters (like | ^ etc.) or group of ...
0
votes
3answers
36 views

How do I loop through a file with awk

I am using this command sed -e '/^*/d' $WORKFILE | awk -f test.awk >> $OUTPUTFILE in a ksh script to take a file of 274567 lines like this * * * * * syopsf00 a0000096 ...
1
vote
1answer
46 views

Compare two Arrays in KSH and output the difference

I am not extremely familiar with KSH (Actually just started using it) and I am having problems with trying to create a script that will essentially compare two arrays that have been stored and then ...
1
vote
1answer
82 views

Redirection. What is “<>”, “<&” and “>&-”?

"<>" This operator I saw few months ago on the one site, but I don't remember what does it mean. Maybe I'm wrong and ksh has no "<>". "a<&b" I know that this operator merge input stream ...
2
votes
1answer
18 views

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?
1
vote
1answer
46 views

SQLPLUS value in variable- not working from crontab

I am trying to store sqlplus value to a variable in Linux. Script is working fine when triggered manually. But value in variable is not stored when the script is called from crontab. Code: ...
1
vote
1answer
138 views

-ksh: pushd: not found

I am new to Unix and I am trying to used pushd, popd and dirs in SUSE Linux but I am getting -ksh: pushd: not found while I try to check pushd which pushd which: no pushd in ...
0
votes
1answer
48 views

For loop brackets - C like syntax

When i am using the below syntax to iterate why two brackets are needed ? for (( expr1; expr2; expr3 )) do command1 command2 .. done and the below code doesn't work ? and throws error "syntax ...
1
vote
1answer
163 views

Remote ssh command not sending echo variable from a ksh script on AIX

I'm need to get the value of a variable from a remote host in a script using SSH and have to source an environment file first that does a shift at the end of its run. The command works locally and I ...
3
votes
2answers
144 views

forward function and variables into sudo su - <user> <<EOF

I have declared functions and variables in bash/ksh and I need to forward them into sudo su - {user} << EOF: #!/bin/bash log_f() { echo "LOG line: $@" } extVAR="yourName" sudo su - ...
4
votes
1answer
98 views

How is ksh93 so fast?

So, in general, I tend to look to sed for text processing - especially for large files - and usually avoid doing those sorts of things in the shell itself. I think, though, that may change. I was ...
1
vote
1answer
92 views

How to run “&” operation sequentially

From my script I am running following commands: SCRIPT_1="ksh -x script1.sh & ksh -x script2.sh"; SCRIPT_2="ksh -x script3.sh & ksh -x script4.sh"; eval $SCRIPT_1; sleep 20s; eval ...
2
votes
2answers
118 views

Using Diff on a specific column in a file

Will it be possible to use diff on a specific columns in a file? file1 Something 123 item1 Something 456 item2 Something 768 item3 Something 353 item4 file2 Another 123 stuff1 Another 193 ...
0
votes
0answers
26 views

ksh if/elif statement not working with || and && [duplicate]

NOTE: Pertaining to the duplicate referenced - I already tried that prior to posting here and got the exact same results. I've posted an additional section below with this so that you can see what I ...
0
votes
1answer
38 views

ksh your own shortcuts, aliases, settings each login?

I need to set up some handy dandy keyboard shortcuts as I am fed up with setting up various aliases each login time from scratch. what is the most convenient way to do this since I don't have the ...
-1
votes
1answer
27 views

split in different lines every match of the same line [on hold]

I have a code like these: , Select code from sales group by id.... I would like to have three lines like these: , Select code from sales group by id...... Someone can help me how could I do ...
0
votes
0answers
20 views

Sigstop when trying to run script?

I am trying to list out all commands by users, unfortunately I hit a weird sigstop that I am not sure how to diagnose? #!/bin/ksh echo '[' for USER in `cut -d: -f1 /etc/passwd |sed '/^#/ d'`; do ...
2
votes
1answer
48 views

Get commands a user can run from /etc/sudoers?

I need a shell (ksh) script that can be executed locally on a box that will return a list of users who have sudo access to a server and what commands they can run. For example I want to know that ...
3
votes
3answers
353 views

awk + print lines from the first line until match word

I want to print all lines from file until the match word please advice how to do that with awk for example I want to print all lines until word PPP remark the first line chuld be diff from AAA ( ...
1
vote
2answers
46 views

disk space by individual user

I have around 50 user folder under etc/main/ folder. Now i want to get 10 large space user folder detail. Note: I don't want sub-folder of each user..I am using Ksh script. Example: /etc/main$ ...
4
votes
1answer
74 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 ...
1
vote
5answers
88 views

How to sort on two fields of numbers

I have a list of filename like so: epdb_0_0.pdb epdb_0_10.pdb epdb_0_11.pdb epdb_0_12.pdb epdb_0_13.pdb epdb_0_14.pdb epdb_0_15.pdb epdb_0_16.pdb epdb_0_17.pdb epdb_0_18.pdb epdb_0_19.pdb ...
0
votes
2answers
48 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
5answers
103 views

Regular Expression for Mixed cased words

I want a regular expression that will help me identify if a certain pattern is present as a mixed case in a sentence or not. Say: Fox juMPed the rock Now, I want to find that if the pattern ...
2
votes
6answers
99 views

Getting the matched word exactly

I have looked through a number of question but they do not satisfactorily reply to my question. I need to print words that match the pattern exactly not the lines containing that word. For example: ...
1
vote
3answers
168 views

How to sort the filenames shown in grep command based on timestamp?

In the following command, how can I get the file names based on its timestamp $ grep "exit 0" a* a1.txt:+ exit 0 a2.txt:+ exit 0 a3.txt:+ exit 0 a4.txt:+ exit 0 a5.txt:+ exit 0 $ ls -latr ...
1
vote
4answers
67 views

How to do grep even if the file is not present?

I am doing something like this in my code file_nm=`ls -latr *abc*` if [ `grep "search_txt" "$file_nm" | wc -l` -gt 0 ] then echo "string found" else echo "string not found" fi If the file_nm is ...
2
votes
2answers
66 views

How to wrap the comma delimited values to the next line without disturbing the other fields using awk or ksh

I have the following input, in which some of the values are comma delimited. I would like decouple each value and print it in the new line. I tried many ways in awk, but no luck. If I have three ...
0
votes
1answer
65 views

How to copy lines in awk command? (ksh scripting is preferred)

I have the below index file key1|1|1001 key1|1|2001 key2|2|3001 key2|2|4001 using this index file, I have to update my main file key1|1000|2000|3000|4000 key2|1000|2000|3000|4000 The ...
2
votes
2answers
221 views

Meaning of \ before environment variable

In ksh on an old Solaris box I used: export PS1="$PWD $" to set the prompt to the current directory. It works great until you cd elsewhere, then you see that it's not evaluating PWD each time. I ...
2
votes
1answer
164 views

set -xv behavior in ksh vs bash

Normally I like to have all of the debug output of a script go to a file, so I will have something like: exec 2> somefile set -xv This work very will in bash, but I have noticed in ksh it ...
0
votes
1answer
670 views

Null message body; hope that's ok

I have the following command below as part of a cronjob. When I run the command via cron or at the command line, I get Null message body; hope that's ok. The contents of the email are empty but when ...