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
2answers
30 views

How to use awk in a while loop?

while read PWW do cat user/dump/bar.txt | awk '/${PWW}/{print $2}' >> user/dump/out.txt done < user/dump/foo.txt foo.txt: 2100001b32 2100001b38 3100001b35 4100001b28 5100001b46 ...
1
vote
2answers
40 views

Substrings in shell script

Am trying to get a substring from a string but am getting the error: ${curr_rec:3:4}: bad substitution #!/bin/ksh get_file_totals() { if [ -e "$file_name" ] then IFS='' ...
0
votes
0answers
25 views

Avoiding heredoc sh[process_number].* files in /tmp directory

I have a .ksh file which logs into sqlplus and runs some queries. The block of code is something as mentioned below: //Other things done in ksh sqlplus -s @connect.sql << EOF Query1 Query2 ...
0
votes
4answers
65 views

Hexadecimal number sequence checker in Linux?

I have a list of hexadecimal number. I would like to check whether they are in sequence or not. That is, they should be consecutive numbers, in increasing order. In other words, there should be an ...
1
vote
2answers
57 views

use SFTP in shell script

I have written a shell script to get the files from another UNIX server. But files are not being copied. Could someone help me what I am doing wrong. sftp username@server:$path get ubpbilp* ./ mget ...
2
votes
2answers
58 views

Reliably identifying the path to the directory containing the running script

There are plenty of answers in SO to address this question: Can a Bash script tell what directory it's stored in? Unix shell script to find out which directory the script resides? And there are a ...
1
vote
1answer
49 views

Pattern matching inside awk

I intend to modify the output of ls -la to display the output of file command. The below command works well for the purpose find /opt -type f | xargs ls -let | awk 'BEGIN { OFS="\t" } { sprintf("file ...
2
votes
3answers
48 views

Search a String in a directory- Get output without filename

I am executing the below command to display the lines which matches the pattern. find ./files/ -name "*.txt" -print0 | xargs -0 grep "5|20150507" And output is ...
0
votes
1answer
43 views

Solaris: How to run a system command on top of awk and combine all output in a single line

Have this peculiar requirement to print files in a given directory in the below mentioned format filename1 <type of file> owner group filename2 <type of file> owner ...
4
votes
2answers
91 views

Checking if a command is a built-in in ksh

How can I check if a command is a built-in command for ksh? In tcsh you can use where; in zsh and bash you can use type -a; and in some modern versions of ksh you can use whence -av. What I want to ...
1
vote
2answers
35 views

Read the file from one Unix server to the other Unix server

I have a Pro*C program which I run on Unix server a but the input file required for this program is on other Unix server b. Whenever I run I have to copy the file from server b to a. Is there any way ...
0
votes
1answer
62 views

FOR loop not looping

I have the below script that uses 2 for loops. for some reason they loop is not looping #! /bin/ksh CURR_PATH='/main/nedcor/flexcube' cd $CURR_PATH for DIR1 in 'WIP' 'INPUT';do echo $DIR1 ...
5
votes
5answers
331 views

How can I safely get the version of ksh?

How can I safely get the version of ksh from within a ksh script? I have seen the following solutions: ksh --version echo ${.sh.version} echo $KSH_VERSION And if the circumstances are perfect, ...
1
vote
1answer
24 views

Is it possible to get working history for multi-line commands in mksh, using vi editing mode?

On my Debian systems, I have always used pdksh as my interactive shell. Originally, command-line history behavior was similar to what I grew up with on platforms like AIX and Solaris. Recently, ...
0
votes
1answer
54 views

How to avoid executing a command if a process doesn't exist

In a korn shell script, I am running expdp. I have made the script to where it can be reusable so if a later process fails, I can run it again without running the already completed steps. I am running ...
0
votes
1answer
30 views

ksh: Not importing prompt settings from /etc/profile

I am using SUSE Linux Enterprise Server 11 SP3 and I am facing an issue related with a user using ksh. I have created a user as follows: ...
0
votes
1answer
27 views

Retrieving prompt information in ksh?

If there is a prompt being read for a value such as: #!/bin/ksh echo "What is your name?" read name username=$name rcmd machine1 grep $username /path/locnames >> namefile rcmd machine1 cat ...
3
votes
4answers
112 views

Shell usage of “:-” and advantage

I found this line in a korn shell script: var=${var:-/temp} I am able to figure it out what it is doing $ var=/data $ var=${var:-/temp} $ echo $var /data $ var= $ echo $var $ var=${var:-/temp} $ ...
4
votes
1answer
28 views

Enabling completion with tab on an old ksh on SystemV

Is it possible to make completion with Tab like in bash? Currently I use Esc twice, can this be changed to a tab?
-2
votes
1answer
68 views

How to create a script that merges two files to get a specific output in the korn shell? [duplicate]

I'm currently working on trying to merge two files together on unix and I REALLY need help. I'm very new to Unix (and this site) and would appreciate any assistance. first file: Tom 313.455.6786 ...
0
votes
1answer
29 views

KSH on old unix systemV: search history

I have set a good ksh environement on old unix PATH=$PATH:/usr/lib/acct:/usr/sbin:/sbin:/usr/ucb export PATH EDITOR=vi FCEDIT=vi export EDITOR export FCEDIT HOSTNAME=`uname -n` HISTSIZE=500 ...
0
votes
1answer
56 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: ...
1
vote
3answers
42 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
276 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
34 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
297 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
90 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
65 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
66 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
71 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 ...
3
votes
2answers
161 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
106 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
63 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
66 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
48 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
2answers
72 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
25 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
169 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
53 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
75 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
53 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
140 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
25 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
45 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
57 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
234 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
50 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
58 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
126 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
146 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 ...