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

KSH script having trouble reading in variables line by line

For starters, I'm not the most advanced scripter. I was asked to create a script that would search through a directory for print files older than 14 days and move them to an archive directory. There ...
3
votes
2answers
44 views

Remove old files in a directory except files present in an exception file

I am writing a shell script to delete old files (older than 60 days) in a directory except few files and these file names are maintained in an exception file present in another directory. I know the ...
0
votes
1answer
45 views

Up arrow at an empty prompt in ksh93

This is a request for explanation or pointer to documentation. I'm a KornShell93 (ksh on Mac OS X or ksh93 elsewhere) user. I like the shell for its relative simplicity as an interactive shell and ...
0
votes
0answers
30 views

Delete files based on files name comparing to sysdate? [duplicate]

I've files with a prefix name like this: 20160623a.dat 20160623b.dat 20160623c.dat 20160623d.dat [20160623] is a prefix that generated with date "+%Y%m%d" command. I'd compare this prefix to ...
10
votes
1answer
286 views

How does ksh93 avoid forks in command substitution

Given cmd='fun(){ echo "$@"; }; fun $(fun $(fun hi))' shells tend to need to make 2 forks to make it happen strace-f(){ strace -f "$@" 2>&1; }; for sh in dash bash zsh ksh; do ...
1
vote
0answers
14 views

Returning an array from a ksh93 function

I would like to return an array from a function in ksh93. At this point, using the following method, the contents of the array are passed as a single element even though, in the fonction, the array ...
1
vote
1answer
43 views

Output broken when appending output of sql query in ksh

I'm very new to scripting. I would like to add the output of the sql function given below to another variable for example: month_end () { mdate=$($SQLPLUS_HOME/sqlplus.exe -S $DBC << END set ...
0
votes
1answer
22 views

AIX ksh script to define exported variables locally based on a remote file's definitions

I have to get "export" lines from a remote file on another server, then set the current sh session env dynamically. However, echo with export doesn't seem to work. echo `export CONFIGA=...
1
vote
1answer
39 views

Automating ftp processes

My shell: bin/ksh My system: Linux 2.6.18-406.el5 #1 SMP Fri May 1 10:37:57 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux My script: ftp -divn XXX.XXX.XX0 << EOF! user user pass cd /home/dir1/...
0
votes
1answer
14 views

Create a file with the concatenated information of all files that start with “file_excel”, in chronological order

my system: Linux 2.6.18-406.el5 #1 SMP Fri May 1 10:37:57 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux my shell: /bin/ksh My issue: I want to create a file: data_excel with the information of the ...
1
vote
1answer
26 views

Extract creation date and modification time of file in Sunos [duplicate]

I want to extract creation date of a file and modification time. The format should be( yyyymmddhh24miss) My unix shell /usr/bin/ksh The file: file.txt My system: SunOS 5.10 Generic_150400-23 sun4v ...
2
votes
2answers
39 views

Record going to next line in a PIPE separated file

I have a pipe separated file with the format something like below 1|ABC|11|DEF|111 2|ABC|22|PQR ST UW|222 3|ABC|33|XYZ|333 4|ABC|44|LMN|444 Now for the line starting with 2 when I try to insert ...
0
votes
3answers
94 views

stat command not found

I want to execute stat command in my unix shell /usr/bin/ksh: Input: /bin/date +%Y%m%d%H%M%S -d "$(/usr/bin/stat -c %x find.txt)" And the output: /usr/bin/ksh: stat: not found My system: SunOS ...
-2
votes
2answers
190 views

Unix for loop and grep combined ksh hp-ux

What if you have 5 or 6 files, specific files .biz in a directory, and you want to store them one at the time in a variable $file, and apply a set of command until no more .biz file are found in the ...
0
votes
1answer
35 views

Issue passing parameters to /bin/sh -c

I am trying to use /bin/sh -c to execute a .sh script with a date parameter. The -c option is not optional as it's what the framework my team has uses. I can't get the date epoch parameter to pass ...
2
votes
4answers
87 views

How to format a bash loop using sed, awk, grep, and wc

So I have a text file that I need to get extract specific lines out of and count the number of times a number in a specific column appears. I have about 100 or so of these files. I can get it done ...
1
vote
1answer
54 views

How to organize files in main directory into smaller amount of files in sub-directories [duplicate]

I have a directory of 150 files that I wanted split into sub-directories of 25 files each: 1-25 into dir1, 26-50 into dir2, and so on. How can I accomplish this? dir1/fre_4_g2_c3654214.h3 dir1/...
0
votes
1answer
56 views

Prepare update command using sed

I have a output file that contains 3 different column data- ['AARF'],SAMPLE12,2016-01-05 12:00:00-0500 ,529OFFST,2015-04-16 08:04:21-0400 "['EPROSP_IWS', '...
0
votes
2answers
42 views

pausing a loop in AIX to wait for user input

I'm searching for a scripting mechanism that can realize the following idea. Loop over a list and stop/wait on "read x" until the next input from a user. I know the following script is not working! As ...
-5
votes
1answer
77 views

Exit a program by pressing the key q

I have wrote a shell script in which I would like to include the functionality to exit the program by pressing the q key. Can I do that? Here is what I currently have: #!/bin/ksh echo "Press Q to ...
0
votes
1answer
29 views

Checking that $((a * b)) evaluates in my own shell [closed]

POSIX seems to define that a shell should be able to evaluate like a calculator the expression $(( a * b)) where * is a binary operator +, - or *. I programmed such a calculator for my own shell and ...
1
vote
2answers
28 views

Variable assignment in a ksh script

I am viewing a ksh script and I see a function where the variable has been defined as below. Can anyone explain what exactly the below assignment of variable means in ksh script? temprule="\$${...
1
vote
2answers
46 views

How to benchmark different shells [closed]

I want to know if shell 1 is better for a job than shell 2 with a test that I handle maybe with shell 3 for example ksh, dash, bash or zsh. I use a test script that builds my projects, starts it,feed ...
0
votes
3answers
51 views

sed substitution

I have a string as follows: /test/test/ 12 /test/test My goal is to turn it into: /test/est/ 12 /test/test This is the command: echo "$x" | sed 's@\(/*/\).@\1@g'" I am using at the moment but ...
-1
votes
1answer
39 views

for loop to evaluate multiple directories and execute command

I was editing a shell script and I want to know how can use for to use all directories listed by a list or variables and then execute a command. Example: I have this directories: /dirname1/app1 /...
0
votes
1answer
17 views

KSH password generator

How to make sure the generated passwords contains all these special characters: ?!/=\? Currently I'm using: pwd_usr["$i"]=`cat /dev/urandom|tr -dc "a-zA-Z0-9-_\?\!\=\/\"|fold -w 15|head -n 1` But ...
2
votes
3answers
755 views

Why can't Korn Shell do ctrl-r?

If I use PC-BSD with the default shell (Korn) then Ctrl+r doesn't work. Why won't it work? Ctrl-r was introduced to search your history in the late 1970s or early 80s and my BSD still can't do it (...
0
votes
0answers
21 views

search insert and replace [duplicate]

I want to search each record (records are defined by blank lines) in a file for the pattern NAME#AAAA. If it matches, then insert an # in front of the record's AGE line and move that line to the top ...
0
votes
0answers
16 views

I want to search for a pattern in a file. If the pattern matches, it should check for second pattern and replace it with another pattern file [duplicate]

I want to search for a pattern in a file. If the pattern matches, it should check for second pattern and replace it with another pattern INPUT FILE Name#AAAAA std 1 sec c age 5 Name#BBBB std 2 ...
0
votes
2answers
37 views

How to list files with a particular pattern created in the last 30 days in unix [duplicate]

I'm using the below command but it is not working find . PYRLLPS_GL_201610D2* -maxdepth 1 -mtime -30 I get the below error find: bad option -maxdepth find: [-H | -L] path-list predicate-list
1
vote
0answers
47 views

Following the move of the source code from the AT&T repo to Github, has anyone built ksh93, AST, or UWIN from it, on a Cygwin platform? [closed]

Following the move of the source code from the AT&T repo to Github, has anyone built ksh93, AST, or UWIN from it, on a Cygwin platform? I refer to another thread on this forum: Is the shell ...
0
votes
1answer
63 views

shell script works fine when executed in terminal, but errors out when ran as concurrent program

I'm trying to add the below string manipulation commands in my existing shell script. #!/bin/ksh y=${#text} echo "Length of text: $y" echo "Last _ is in column $((${#text} - ${#end}))" echo "Our ...
1
vote
1answer
52 views

bash or Ksh quotes and command exec [duplicate]

while creating a script I am facing currently a "strange" issue that so far I am unable to fix. typeset -r SERVICE=\"ldap://localhost:10389\ ldaps://solsrv02.internal.vbox:10689\ ldaps://solsrv02....
1
vote
1answer
99 views

How to make “Ctrl + L” to clear screen in ksh under Red hat linux?

I am using putty to connect to the Red hat linux server. My shell under linux in Korn shell. I am used to clearing screen with the "Ctrl + l " combination. Some how this combination is not working ...
-1
votes
1answer
44 views

What characters are allowed in an alias?

I am confused as which are the allowed characters to be used in alias? With a function defined as f(){ echo "yes"; } Is it possible to create an alias like: alias fé='f' ### works alias :='f'...
0
votes
1answer
48 views

Unix, create file based on command [duplicate]

I have a command, but I want to get the results into a .txt file I can open. How do I alter my command to allow the results to be put into a text file. I plan to transfer this .txt file to my local ...
3
votes
2answers
82 views

What does '-size +0' mean in shell 'test' command

I came across a if statement like this: if [ -f <file path> -size +0 ] I know that -f checks for file existed, but what does this -size +0 do here? I can't get help form man page also tried ...
1
vote
2answers
43 views

How to receive a mail whenever a file gets deleted?

I've accidentally deleted my cron using crontab - command and now the file under /var/spool/cron/crontabs directory got deleted. I would love to have a script which mails whenever my files under /var/...
1
vote
0answers
36 views

Conditional expressions in shell: What are the differences between [ vs [[ [duplicate]

I just wondered about some people writing if [[ <expr> ]]; then ... in answers here when I out of habit would use if [ <expr> ]; then ... Doing a quick research reveals that [[ ]] ...
5
votes
3answers
189 views

Why zsh and ksh93 chose to be non-compliant in pattern matching?

POSIX documentation for pattern matching said that: An ordinary character is a pattern that shall match itself. It can be any character in the supported character set except for NUL, those ...
1
vote
1answer
70 views

How to escape a range of wildcards in unix shell script?

I need to execute the following Oracle SQL in unix crontab. The query is as follows: select count(*) from tbaadm.htd where cust_id is not null and pstd_flg = 'Y' and del_flg = 'N' and tran_date = (...
3
votes
3answers
44 views

Assigning upper case variables to commands

While trying to decipher some scripts written by former employees of my current company, in many of the scripts, I came across the following statements which assign variables to some commands as shown ...
0
votes
1answer
29 views

Parsing a delimited in ksh as command argument

My system generates a flat file with 7 arguments : Field1,Field2,Field3,Field4,Field5,Field6,Field7 Field1,Field2,Field3,Field4,Field5,Field6,Field7 Field1,Field2,Field3,Field4,Field5,Field6,Field7 ...
1
vote
1answer
63 views

comparing decimal point values in if statement

Today I was trying to compare two values and surprised what I saw. I didn't find any good suggestion anywhere. Could any one please help? if [ 10.94 -gt 10 ] then echo True else echo False fi I ...
0
votes
0answers
19 views

Unable to print msg to console from subscript

I am calling a ksh script file from another as given below runCommand "qc_data" Here qc_data is a ksh script file. in runCommand i execute the command as below function runCommand { ...
2
votes
1answer
58 views

Two input pipes through file descriptor shuffling and /dev/fd

I want to pipe two programs into one. If my shell supports it, I can use Process substitution. For example, to list the common lines of two files in indifferent order, I can use comm -12 <(sort a) ...
0
votes
1answer
37 views

how to concatenate Login, pwd and @server variables?

how to concatenate Login, pwd and @server variables ?? ex: export Login_va="Login" export pwd_va="pwd" export server_var="@server" echo whenever sqlerror exit | sqlplus $Login/$...
1
vote
1answer
101 views

Issue with resize and stty on remote ssh script?

Scenario: Source host (Solaris 5.10, KSH), im trying to run the following script named sample.ksh on source #!/bin/ksh set -x Rediscover () { ssh user@hostB ./scripts/test.ksh } Rediscover exit 0 ...
-2
votes
1answer
51 views

KSH for generating 'n' of rows for a table dynamically : Issue with if else statement

I need to generate billion of records in a text file for table loading purpose. My destination table defination is: CREATE TABLE txnrecords12( txnno int, txndate string, custno int, ...
0
votes
4answers
38 views

Alias for listing top file and directory consumption - shortest way?

function isaix { echo "alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" >> ~/.kshrc; } function islinux { echo "alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" >> ~/....