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

0
votes
1answer
33 views

Color diff output

I am new to unix I wanted to format the unix files conditionally , I am currently working on diff command and wanted to know if it is possible to format the text of the diff command output. Example: ...
-2
votes
0answers
29 views

Unix KSH/Bash : Diff files for selected fields/columnwise only {GNU Bash 4.2 Environment}

I have two files: F1: abc|abc|abc|abc|abc| abc|abc|abc|abc|abc| abc|abc|abc|abc|abc| F2 abc|abc|abc|abc|abc| bcd|bcd|bcd|bcd|bcd| My questions are as follows: Suppose both files will have same ...
1
vote
3answers
22 views

Unix - ksh test if multiple variables are 0

So basically I want to test if 3 variables are 0. If one of them is not it should report it. This is what I got: if [[ $result -ne 0 && $resultmax -ne 0 && $resultmin -ne 0 ]] ...
2
votes
3answers
151 views

KSH/BASH Maximum size of an Array

What is the maximum size of array for ksh and bash scripting ? Example: Suppose I have an array of 10 elements than what will be maximum number of string count that a particular index of an array can ...
0
votes
0answers
23 views

KSH/BASH Comparsion b/w Two Array and then logical OR operation at other function (GNU bash 4.2 version)

I am new to unix and learning it basics. I wanted to compare same index of two different arrays and on the basis of comparision I wanted to put a data to other array. First I tried to use it ...
4
votes
3answers
232 views

KSH - if/then/else vs. double amps (&&) and double pipes (||)

I am wondering what are the best practices regarding if/then/else ; I tend to use the following form (because I find it easier to read) #!/usr/bin/ksh # [[ -f /path/to/target/file ]] && { ...
1
vote
3answers
67 views

UNIX KSH/BASH Call by Reference using Array (at GNU bash 4.2)

I am new to Unix shell scripting My code is as follows: i=0 for var in 'a' 'b' 'c' 'd' 'e' do content[i]=var ((i=`expr i+1`)) done a=10 b=50 c=40 d=90 e=100 Now I wanted to print the local ...
1
vote
1answer
52 views

KSH/bash for File Creation Dynamically

I am new to ksh and unix and I am learning it: I wanted the following:I have a directory name tmp on that directory on basis of FileName Category I wanted to create 'n' number of files dynamically. ...
1
vote
1answer
60 views

Unix Shell : Array assignment not working [duplicate]

I am new to unix shell I am learning array by following code source_array_list[0]="a" source_array_list[1]="a" source_array_list[2]="a" source_array_list[3]="a" source_array_list[4]="a" ...
1
vote
1answer
46 views

Unable to track error

I am new to Unix shell scripting, While running my program I found the following errors today.ksh[36]: test: 0403-004 Specify a parameter with this command. sed: 0602-419 Cannot find or open file ...
-1
votes
0answers
27 views

Can we connect Winscp using power broker?

I am connecting through power broker i.e pbrun command via putty to server. Can someone guide me, How can I connect to the server if I am using WinSCP because authentication will be done only I ...
3
votes
2answers
126 views

Unix bash Sed command Combination on one file

I have a file containing strings delimited by any of the following undesired characters: < > | <space> It looks like this: ... > Test Item|Test Item ... The above ... ellipses ...
1
vote
2answers
48 views

grep or find a pattern in all directories [duplicate]

I have an account number 1234-5678, I am trying to find it in all files of directories. I used the below command but no result found. grep "1234-5678" */ Please can someone help me how to find it in ...
1
vote
1answer
58 views

How can I skip empty files with sed?

I am using sed like this: sed -e 's/ *| */|/g' ${array_export_files[$loopcount]}>>$TEMPDIR/"export_file"_${testid}_${loopcount}_$$ under a while loop but problems come when the file is ...
3
votes
1answer
30 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
44 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
30 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
23 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
164 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
52 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
55 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
31 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
83 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
34 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
47 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
211 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
49 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
37 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
125 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
105 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
155 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
28 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
99 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
138 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
24 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
21 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
39 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
97 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
419 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
62 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
38 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
168 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
93 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
74 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
205 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
66 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
320 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
370 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 - ...