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
6answers
1k 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

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 ...
0
votes
2answers
1k views

ksh - map Ctrl-D to exit shell

I would like to know how we can map the keys Ctrl-D in ksh to exit the shell as it does in bash shell. Not much familiar with key binding in ksh. Edit See my comments below. $ echo $0 bash $ exit ...
2
votes
4answers
73 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 ...
0
votes
2answers
180 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
1answer
48 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 ...
-5
votes
1answer
57 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
55 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
34 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 ...
15
votes
4answers
10k views

Executing user defined function in a find -exec call

I'm on Solaris 10 and I have tested the following with ksh (88), bash (3.00) and zsh (4.2.1). The following code doesn't yield any result: function foo { echo "Hello World" } find somedir -exec ...
1
vote
2answers
40 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
1answer
28 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
26 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? ...
0
votes
3answers
49 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 ...
8
votes
2answers
1k 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 ...
4
votes
1answer
833 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
2
votes
1answer
466 views

How to have a bash script perform a specific action on errors of _each_ command?

Similarly to set -e performs an exit on "uncaught" $? != 0, I'd like to have this event trigger the execution of another command, e.g. a logger call. How can this be done?
1
vote
2answers
346 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
votes
1answer
38 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
15 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
738 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
30 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
36 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
54 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 ...
44
votes
8answers
102k views

Delete First line of a file

How can I delete the first line of a file and keep the changes? I tried this but it erases the whole content of the file. $sed 1d file.txt > file.txt
2
votes
2answers
980 views

xterm resizing causes shell to mess up

I'm using reflection x, which uses xterm as the terminal emulator. If I maximize and minimize the window several times, when I try to access previous commands, the text becomes messed up. The issue ...
1
vote
1answer
47 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\ ...
1
vote
1answer
84 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 ...
8
votes
6answers
5k 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 given the right circumstances, each ...
12
votes
2answers
13k views

Exporting a variable with dot (.) in it

How to export a variable which has dot in it. I get 'invalid variable name' when I tried : export my.home=/tmp/someDir -ksh: my.home=/tmp/someDir: invalid variable name Even escaping metacharacter ...
-1
votes
1answer
35 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 ...
0
votes
1answer
42 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 ...
4
votes
3answers
4k views

Get the number of files that match a pattern in a directory and delete the oldest one

I'd like to do the following: Get the number of files in a given directory that match a given pattern, for example: ExtractBackup_{date}.tar.gz If that number is 2 or higher, delete the oldest file ...
1
vote
2answers
39 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 ...
0
votes
1answer
28 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
3k views

Null message body; hope that's ok

I have the following command below as part of a cronjob. When I run the command via cron or at the command line, I get Null message body; hope that's ok. The contents of the email are empty but when ...
3
votes
2answers
78 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 ...
5
votes
3answers
180 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
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 [[ ]] ...
1
vote
1answer
67 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
41 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 ...
1
vote
4answers
4k 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: ...
1
vote
1answer
215 views

How can I see history of the “at” command in AIX?

I'm experiencing a strange problem where occasionally the at command appears to not be running the command I've configured it to run. For example: at -t 201510071042 runsomescript <Ctrl-D> ...
1
vote
1answer
51 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 ...
2
votes
1answer
631 views

Tutorial about key mapping in KSH in EMACS mode

Are there any good tutorials to learn about key-mapping in Korn Shell (AIX) in EMACS mode ?
0
votes
0answers
15 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
54 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
32 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 ...