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

3
votes
1answer
21 views

typeset and return status in ksh

I'd like to be able to declare a local var as the result of a command AND to be able to capture return status of command. Something like this: #!/bin/ksh typeset -r command_output=$(command) typeset ...
1
vote
1answer
35 views

Indented here document causes a syntax error

I have the following code fragment in my shell script and have a bug that I can't seem to pin down a reason for despite some research. When I run the code as below the script exits with a message ...
1
vote
1answer
18 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
vote
1answer
21 views

zwrite handling of “@” symbol

I've been using zwrite to create simple message popups in AIX, and it handles @ symbols weirdly, even when they're strong quoted. I'm running these commands in ksh. As an example, echo '1 @ 2 @@ 3 ...
3
votes
2answers
159 views

sed command doesn't return what I want

My document doc.lst is compound with numbers and letters like this : 01 ABC and I want to take only the "ABC" part. I tried this, but it includes the numbers in my result.lst. sed -n -e ...
1
vote
1answer
51 views

A basic function that doesn't work [duplicate]

I've tried several modifications to see why it's not working, but I can't find the answer. Here is my code, this is in french but this is just a normal fonction that ask to the user if he's ready to ...
1
vote
1answer
42 views

Processing output from an sqlite db into a ksh array with spaces

I am querying an SQLite3 database like so: input=$(-separator "," "SELECT field1,field2,field3 FROM table1") and get this result: Red,Yellow is a color,Blue I need to insert this into an array, ...
1
vote
1answer
26 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
67 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
22 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
31 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 ...
2
votes
1answer
36 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
199 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
46 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
32 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
4answers
123 views

How to insert a variable in a variable in a random place?

Q: How can I insert variable $b to a truly random place in variable $a? Example INPUT variable content: $ echo $a árvíztűrő tükörfúrógép $ echo $b ZZ OUTPUT $ ./somemagicscript.sh árvíztűrő ...
1
vote
2answers
69 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
113 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
26 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 ...
2
votes
4answers
89 views

How to highlight given string in given place?

How can we modify this: <a href="http://foo.bar1">asfdlksafbar1qsasadf</a><br> <a href="http://foo.bar2">svasfbar2saldkfj</a><br> <a ...
4
votes
1answer
107 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
20 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
35 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
82 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
354 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
54 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
37 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
88 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
87 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
19 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
57 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
175 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
56 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
252 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
236 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
103 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
113 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
173 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
43 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 ...
0
votes
0answers
21 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
55 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
497 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
49 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
96 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
94 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
57 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
117 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
101 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: ...