Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [ksh]

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.

1
vote
1answer
34 views

elif statement is not getting executed in unix shell script

#!/bin/ksh print -n "\nEnter the client ID : " read clientID print $clientID data=$(grep jms/erms/$clientID /export/home/a0706838/test.txt;) print "\n $data" getClientID=$(echo "$data" | awk '{...
0
votes
2answers
52 views

How could I know inside a script if stdout has been redirected for it?

I have a script in ksh; depending whether there is a redirection from the command line, I redirect the output via a exec 1>file. How can I test from inside the script itself if the command calling ...
-2
votes
2answers
35 views

use the file contents line by line and execute [closed]

file.txt servername1:DBNAME1:/u01/app servername2:DBNAME2:/u01/dbs servername3:DBNAME3:/u01/app1 I want to use above file contents line by line and execute it in shell script command1 hostname=...
-2
votes
1answer
46 views

Extract string followed by specific word/symbol

I have two lines as shown below in my input file input.txt and I need to extract claimStartDate from first line and claimEndDate from second line. <ProfessionalClaim paymentIndicator="P" ...
-1
votes
1answer
38 views

Perl script not found when executed from a different directory than the current one

I am using perl64 on Windows 10 with UWIN installed. I wrote a perl script, sv2jb.pl, which runs fine when invoked under ksh by just typing its name, and when it is in the current directory. I then ...
3
votes
2answers
64 views

A Unix AIX variable without a $ symbol?

I'm trying to debug an existing program and found an if condition without $ symbol prefixed to it. Values are: dt_val=1234 prev_dt_val=1234 If condition goes like: if [ dt_val -eq prev_dt_val ] ...
0
votes
1answer
27 views

korn shell Unable to substitute ' ' (2 quotes) with ' (single quote) in a string variable

I am trying to substitute ''2019-01-14'' to '2019-01-14' in a varible $STG. I tried various techniques echo ${STG//''/'} echo $STG | sed -e s/'\'\''/'\''/g many more none of the equations are ...
0
votes
3answers
41 views

unix awk match a string and perform delimiting

I'm checking the ping connectivity checks from a host and that would ssh to another jump host and will perform ping communication. I would like to print the successful packets pinged count using awk. ...
0
votes
2answers
40 views

Move the oldest files into a directory, source directory has more than 10,000 files constantly incoming

I am working on a command to move the x number of oldest files(FIFO) into a directory, is it better idea to pipe the "find" result into "ls" or just use the "ls" .. please suggest. ls -ltr `/bin/...
1
vote
0answers
18 views

AIX 6.1 versus AIX 7.1 strange behaviour [duplicate]

I have this logic in a ksh script on AIX 6.1 and it works fine. integer loop_count=0 integer sleep_interval=5 integer alarm_interval=60 if (( $loop_count*$sleep_interval%$alarm_interval -eq 0 )) then ...
0
votes
2answers
47 views

Extracting part of string from a file in ksh environment

I have a file that has error messages as per below rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1505) rsync error: error in rsync protocol data ...
1
vote
1answer
23 views

update params of variable ksh88 [closed]

I'm trying to update a variable: FLUX=first DATE=`date +%Y%m%d_%H_%M` justName=$FLUX DIR_LOG=$REP_LOG_TD/DDL_TABLES_LOG/$justName'_'$DATE if [ condition ] then justName=other DIR_LOG=$DIR_LOG fi ...
1
vote
1answer
68 views

Align columns evenly without “column - t”

I have an output file created from a Korn shell script. I need to align the output with spaces evenly. Unfortunately column -t is not available on AIX. Actual File: X1vir1000 x1-DFB127 ...
0
votes
1answer
57 views

How can I adapt this bash progress bar function for AIX ksh88? [closed]

I have a bash script for progress bar and I use it when I work in bash: #!/bin/bash prog() { local w=80 p=$1; shift printf -v pt "%*s" "$(( $p*$w/100 ))" "";pt=${pt// /.}; printf "\r\e[...
0
votes
2answers
29 views

How to sum value of specified column by specific date in kornshell?

I'm working in a unique validation framework that validates data. For each validation job there is a SQL job with an accompanying KSH job (kornshell). The SQL queries something in the database, and ...
2
votes
1answer
41 views

Does ksh93 support +o type options with its getopts(1) builtin?

ksh93 supports long options the same way as introduced by Sun Microsystems in Spring 2004 for getopt(3), Bourne Shell and ksh88. You may e.g. use: getopt(argc, argv, "V(version)"); to establish a ...
1
vote
0answers
22 views

ksh keybind trap

I am trying to follow this code sample http://www.kornshell.com/examples/keybind # Example from page 98 typeset -A Keytable trap 'eval "${Keytable[${.sh.edchar}]}"' KEYBD function keybind # key [...
5
votes
0answers
68 views

Correct treatment of quotes in parameter expansions

Using the default value of IFS, consider unset var set -- ${var:-"hello"} echo "$#" This prints 1 as the parameter expansion expands to the single string hello. unset var set -- "${var:-"hello"}" ...
0
votes
0answers
22 views

How to iterate pattern by other one?

I have the bellow output. I try to iterate same times the Date and Time: Month Day Year HH:MM:SS for each Application n.n string found it. =========================================================...
1
vote
0answers
39 views

ksh while loop issue

In ksh, I have a while loop that reads two files. If current line of file 1 is Y then echo the current line of file 2 into new file and if current line of file 1 is N echo the string waste in winscp. ...
-1
votes
1answer
35 views

Find Command, I want to use my variables

I have a script that creates a new directory based on User Input, and well as which directory contents it will copy over. Now here is where I am having issues, I have a find command that will replace ...
3
votes
1answer
187 views

OpenBSD - How does one set an alias?

I am running the latest OpenBSD and I cannot figure out how to set a simple alias, something along the lines of cls=clear. I've tried putting it in ~/.cshrc and in ~/.profile. I've tried: alias cls ...
-1
votes
2answers
31 views

file permission error when checking filename in ksh

I'm trying to create a checksum file. The file will have a list of files from the working directory, create cksums for each file, and drop the list of files with their cksums as MD5_<>.txt along ...
1
vote
1answer
189 views

Using korn shell to compare local and remote MD5 over sftp

I am in need of creating and checking checksums between a local file, and the remote file I just pushed. If the MD5 checks, continue, else break. This needs to be in KORN shell scripting because we ...
3
votes
1answer
50 views

How to test if IFS is unset in ksh93?

It seems easy to test if a variable is unset. I know of three ways at least: #!/bin/ksh unset var [ "$#" -gt 0 ] && var=$1 [ "${var+set}" != "${var}" ] && echo set1 || ...
1
vote
2answers
427 views

Removing characters with sed [duplicate]

I am working on AIX unix and trying to remove non-printable characters from file the data looks like Caucasian male lives in Arizona w/ fiancÃÂÃÂÃÂÃÂÃÂ in file when I view in Notepad++ using UTF-8 ...
3
votes
1answer
48 views

chfs does not work in a login ksh shell [closed]

I can't find a reason why chfs command fails in ksh (I open ssh sesion with putty). But when I run ksh or ksh93 in the shell again then it works. Any clues? # alias|grep chfs # type chfs chfs is /...
3
votes
2answers
525 views

ksh - subtract 5 minutes from current time

I need to get the date and time of the command date minus 5 mins. date: 29 Aug 2018 21:56:01 result: 29 Aug 2018 21:51:02 I tried to search on the Internet/forums but most of it involved using the -...
4
votes
2answers
687 views

Script throwing error “=: not found” [duplicate]

Consider: #!/bin/ksh db2 connect to MKTETLPS user ....... using ........ db2 "select count(*) from etl.IDM_COLLAPSE_ORG_DEE c where c.IDM_PROCESS_STEP = 'I' and priority in ( '1','2','3','4','5') ...
11
votes
4answers
852 views

How to put a string search with grep command into if statement?

I want to search multiple strings in two files. If one string is found in both files, then make something. If one string is found in only one file, then make another thing. My commands are the next: ...
0
votes
1answer
35 views

How to write in new file if are occurrences in another one?

I need to create and write in a new file based in occurrences found in another file. i.e: Occurrence found in first file then write same Occurrence in another one/new to be more specific: "File1": ...
0
votes
2answers
240 views

How can we store the output of a command as an array in Unix shell script?

I want to store the ouput of a command into an array. I tried with the below command which I got from a similar question asked here. Please find below the shell comamnds I used: #!/bin/ksh mailx -H &...
0
votes
7answers
175 views

how can I increase the performance for below code

Below is my script which is having lot of performance issue #!/usr/bin/ksh while read i do x=`echo $i |cut -d"|" -f2` rem=`expr $x % 62` echo "reminder is " $rem quo=`expr $x / 62` echo "...
0
votes
0answers
144 views

invalid char '@' in expression awk output

I have an awk command on ksh script, the command extract fields from a log file to then struct them in new one. ultimate=$(grep -oP 'Time:\K.*' $log2 | column -t | awk '{print $3,"/","'"$month"'","/",...
0
votes
1answer
190 views

Bash and Ksh background color - PS1

To change the back color my command is : PS1='\[\033[46m\]' This works fine for bash but in ksh it will but a [] in front of my server. Example : Bash : [USER@SERVER] (in color) Ksh : [][USER@...
0
votes
1answer
40 views

Need to match pattern in KSH while parsing lines from file

FILE_CENT="/etc/nsswitch.conf" if [[ $OS = 'Linux' ]]; then if [[ -e $FILE_CENT ]]; then logInfo "nsswitch.conf found in $OS, Proceeding further..." while read -r LINE do if [[ `echo $...
0
votes
0answers
16 views

how to create a array within while loop [duplicate]

I have run the below command to place values to the array the command is working fine but the array does not contain any values. k=0 sed '1d' /path/result_1.csv | while IFS=, read a b c d e f g h do ...
1
vote
0answers
25 views

Extract full function definitions

Given: $ cat test.ksh doit() { doi1() { echo doi1 "$@" } doi2() { echo doi2 "$@" } doi1 a doi2 b } doit functions doit typeset -f doit Why do I get this ...
0
votes
3answers
833 views

How may I find the most recently modified file(s)?

In a directory, I have a number of files, and I need to do something with the most recently modified file with a .txt suffix. Ideally, I'd like to do myutility "$newest" in the end, where $newest ...
2
votes
1answer
2k views

how to solve the error “arg list too long” [closed]

I am running the commnad ls -lt *$ID* this command is working find if I am running separately but with in the script it returns the below error arg list too long. The id is a unique one there is only ...
6
votes
2answers
523 views

Are Here-Strings available in ksh88?

I wanted to extract 3 words from a variable in 3 different variables in ksh script. I used this line on ksh93 and it worked fine: read A B C <<< $line Got this error for the above command ...
0
votes
1answer
44 views

get string from file name using KSH

I have a file name like 'XXAR_CUST_INV_pt_PT_BURST.xml'. I need only "BURST" as result. note: file name can have many "_"'s (Underscores). So, I need string from last underscore and before extension "...
1
vote
1answer
95 views

Why does =~ operator give a syntax error on Solaris while comparing with a regular expression

I used this following piece of code appcount_range="^[1-$APP_COUNT]$" until [[ $APP_OPTION =~ $appcount_range ]] do echo "INVALID CHOICE! Please enter a valid option:" ...
1
vote
1answer
37 views

AIX: it takes 2 execution to see the true result

Why every time I execute my script, I tooks 2 execution before I see the true result, script_dir=/opt/scripts/x186299 smo_log=/oracle/bxcons21/base/admin/bxcons21/scripts/logs error_txt=$script_dir/...
0
votes
0answers
26 views

ksh: multiplication of variables having values with leading zeroes [duplicate]

For the below code written in ksh, phy_col=$(($bits*$mux)) if bits=40 and mux=8 then it works fine but if bits=040 and mux=08 then answer is incorrect. Any suggestions?
1
vote
1answer
51 views

Turn flushing history in ksh after each command (or stop refreshing it)

I have read that ksh, in contrary to bash, flushes its history after each command. This may be good for many, but for me, it drives me nuts! I have several windows opened that are opened for their ...
0
votes
2answers
79 views

IF-ELSE - Y|N response does not work as required

I am just finding it hard to achieve below using for-loop. Your suggestions/help will be really appreciated. Thanks If user responds in upper or lower case then it should accept and convert in ...
7
votes
3answers
1k views

How to subtract two list (fast)? [duplicate]

What is a fast way to subtract two lists1. The lists may be small, maybe a direct way in shell works. Or the lists may be long, maybe external tools are the faster way. Assume you have two lists: ...
0
votes
1answer
73 views

Parsing comma-separated digits in ksh

I have a variable in ksh that can contain no more then 2 comma-separated digits (white spaces allowed). Something like: a="1,2" a="1 ,2" a="1," a="0,0" I want a loop to read through $a exit if ...
0
votes
0answers
36 views

Unix/CGI script not fetching latest script output

I am trying to get a list of files available from a windows ftp server and then do further processing. Using CURL to get the list of file. I am getting the output displayed on browser but it is stale. ...