ksh, short for Korn Shell, is a Unix shell developed in the early 1980s.

learn more… | top users | synonyms

9
votes
1answer
14k views

How to set default screen colours in putty/ssh

I use putty to ssh to linux box. By default I get black screen background with white foreground. To change colours, I go to change settings -> Window/colours and then I set background colours as ...
4
votes
2answers
764 views

How can I keep reading from a pipe even after the pipe is closed?

I've got a ksh script that calls: while read LINE do... The input has been redirected (not shown) so that it reads input from a pipe. The problem is that when the writer to the pipe closes, read ...
4
votes
3answers
2k views

Unix history not working

I'm using ksh on unix and connect through putty. My .sh_history stores all history commands but when I press up arrow nothing comes, please help me.
4
votes
1answer
191 views

Create a file whose size in bytes is the percentage of free space on a disk

I needed a command-line method of creating a file whose size in bytes is the percentage of free space on a disk. I intend to run it via cron every five minutes, but first a shell script will do. The ...
3
votes
1answer
1k views

overriding user defined functions with the same name as system commands

This function exists in one of my users' ~/.bashrc: function rm() { ls $* echo "rm?" read ans if [ "$ans" == 'y' ]; then /bin/rm $* fi } In ...
3
votes
1answer
748 views

Does “ulimit -Su” limit the number of user processes created in interactive login subshells and tmux sessions created therein?

A few months ago, I wrote a set of bash scripts utilizing tmux to create a simple IDE on an AIX 7.1 server. There is a bug in one of my scripts that will sometimes generate user processes very rapidly ...
3
votes
1answer
456 views

Delete old log files in AIX

I am trying write a script to delete old log files in \var\log\applog\nmon on my AIX system. We usually get alerts that the file system is almost full and at the moment delete old files by hand. So ...
3
votes
2answers
462 views

Unix HP-UX ksh recursive find and replace

I am trying to do a recursive find and replace in HP-UX and am missing something. What I have at the moment: find . -name "*.java" | xargs sed 's/foo/bar/g' I know the problem is that it's not ...
2
votes
3answers
4k views

unix command to see the last run command on command line

what is the command to see the previously executed command that was run on the command line ?
2
votes
1answer
34 views

Pipe standard error to file and keep it on standard error?

I have a script (fragment) for which I'm logging output and standard error: #!/bin/sh #... { date "+%Y-%m-%d %T" cd $workdir ls -ltr validfile badfile #example command that provides stdout, ...
2
votes
1answer
95 views

What is the difference between “elif” and “else if” in shell scripting?

I am very new to shell scripting. When I look at some code, written for ksh (#!/bin/ksh) I see there is else if as well as elif used in one script. So, what is the difference between else if and ...
2
votes
1answer
207 views

ksh equivalent of perl $! error reason

Is there an equivalent of $! in ksh, which provides the error string ? $? stores the exit code only.
2
votes
1answer
56 views

unix - sort content of two folders then compare using diff command

How do I sort contents of two different folders before comparing those two directories using diff?
2
votes
1answer
373 views

Up key for XTerm, Korn shell (while vt100 through telnet/putty works) dont work

I am using xterm on korn shell. I have defined in .kshrc as follows: set -o emacs alias __A=`echo "\020"` # up arrow = ^p = back a command alias __B=`echo "\016"` # down arrow = ^n = down a ...
1
vote
7answers
344 views

Is there a BSD equivalent to “!!”?

I often find myself issuing a command that I do not have the proper elevated privileges for. On Ubuntu I could use sudo !! This would issue the same command with sudo privileges. Is there an ...
1
vote
2answers
8k views

Split a string in ksh

I am looking for a quick/easy way to split a string in ksh. It has varied number delimiters (spaces) between each item. Example: value1 value2 value3 Any suggestions/advice?
1
vote
1answer
222 views

Using a while loop to read a file, randomly stops reading the file in the middle [closed]

I have a small section of code that reads a file, $FUNCTION_FILE which contains a list of function names in the format: func1 func2 func3 It will read a line, run the function, and repeat until the ...
1
vote
1answer
108 views

How to write this script in unix?

How can I write a script for finding the files created by a particular user ID in some locations and tar those files in the same location?
1
vote
1answer
576 views

Infinite loop in Terminal (ksh) to launch commands

I'm trying to create a loop in terminal to launch every second during the execution of an script the following command. I don't want to create the loop in .sh script file, i'm trying to do in the ...
1
vote
2answers
106 views

FIND operands and order of arguments

I have a find command that I am unsure if I am placing my arguments correctly. find / -xdev -size -size -262144000c -o -type d \( -name .snapshot -o -name man -o -name Man -o -fstype mvfs \) -prune ...
1
vote
2answers
4k views

AIX : retrieving previous command using up arrow

I know about set -o vi and k and j combinations. I want to map these to up arrow and down arrow so that I can use AIX(ksh prompt) just like bash . Any suggestions?
1
vote
1answer
47 views

Issues using scp to copy a file in Unix

I have a script where i need to get the cksum of the files in a directory from another host. I was able to do ssh to another host and create the file.txt. what i need to do now is to scp the file ...
1
vote
2answers
425 views

Convert Month Number to Month Name

Is there a way to convert month number to name with a script? example: 2013-10-22 will become Oct 22 Thanks. BTW, I don't have the GNU date and my OS is AIX.
1
vote
1answer
2k views

Adding a month to an input date in unix

I need to write a script that asks user for an input date. Then I need to add a month to that date or at least 30 days. Example: Date: 2009-05-12 I need to get 2009-06-12 this code is not working: ...
1
vote
1answer
583 views

Using readline keyboard shortcuts in OSX korn shell

I am using ksh on Mac OS X 10.6 xterm (that is, not using Terminal.app). When I try to browse the command history via CTRL+P or try to move the cursor on my prompt via CTRL+B, only the characters ^P ...
1
vote
2answers
1k views

count words in LIST without separators

I have the following simple ksh code: MY_LIST=first,second,third NUM_IN_LIST=` echo $MY_LIST | sed s"/,/ /g" | wc -w ` print $NUM_IN_LIST 3 [[ $NUM_IN_LIST = 3 ]] && print match but I ...
1
vote
1answer
877 views

Re-redirect STDERR in K/SH?

Once STDERR is redirected, for example to a file, how can it be redirected back to the original file descriptor 2? #!/bin/sh exec 2>/tmp/err print -u2 'log errors to file' exec 2>&2 (how ...
1
vote
1answer
307 views

ksh93 as default shell via ssh

I'm a big fan of ksh93. My hosts' shell account doesn't allow me to configure .login, .profile or chsh to change my default shell. As it is, I am dropped into jailshell-3.2 and I have to invoke ...
1
vote
1answer
671 views

Extract a single file from a tar file to another directory

I have a tar file and I need to extract a single file from it and put it to another directory. I tried this but it gives an error message. It did extract the file but not to the directory that I want ...
1
vote
2answers
448 views

Difference between running commands locally vs using SSH to make remote commands

I am trying to SSH into a remote machine, and run a .ksh file on a that machine to run a Java program. If SSH into the machine with a tool like Putty, and run this command: cd ...
1
vote
1answer
43 views

Interactive Script; Prompt within a loop

How do I prompt a user for input from a shell script (ksh) within a loop in which a file is read? The script reads in a file. In each loop pass the user will be asked if he wants to cancel or not? ...
0
votes
3answers
303 views

What will happen when I 'cat' 'ksh'?

I used the following command in my unix box. $ cat ksh And it gave a rolling log of latin and greek letters and symbols and it kept on going with no signs of stopping. Eventually I had to close my ...
0
votes
2answers
11k views

how to fix Permission denied on directory in unix?

I have a ksh file which will download a zip file from the internet in the /tmp directory with name f.zip Why do I get Permission denied? $ ./downloadbcfi Current name is ...
0
votes
1answer
1k views

How can I make an environment variable available outside of a KSH script?

I have a KSH script that exports an environment variable (export SOME_VAR=123) After running the script my current shell is unaffected and echo $SOME_VAR produces nothing. I tried running . ...
0
votes
2answers
4k views

Tab complete in VI mode KSH 'vi-tabcomplete' gives bad options

When I try stuff like in my .profile: set -o vi-tabcomplete I get: .profile[292]: vi-tabcomplete: bad option(s) Does anyone know of a workaround?
0
votes
1answer
2k views

Find last modified/created file of a certain extension

I created a script file *.ksh very recently and I want to get a list of the last modified/created *.ksh files. I am sure you can somehow do it using find, just not sure how.
0
votes
1answer
189 views

using sed to replace 1 line with a multi-line variable in ksh

I have the following text in a file: XXXX NNNN YYYY NNNN ZZZZ NNNN I want to replace the NNNN to make it look like this: XXXX NNNN DUTY FORECASTER: YYYY NNNN DUTY FORECASTER: ZZZZ NNNN ...
0
votes
1answer
73 views

Solaris: a simple script does not work, single command does

In my Solaris Illumos, I run a simple script: update_drv -a -i '[myhardware]' [driver] svcadm disable stmf svccfg import /mypath/myconfig svcadm enable stmf It does not work and gives me no ...
0
votes
2answers
52 views

Is there a way to show “File not found” or a message alike when using the `find` command?

I'm trying to check the existence of several files, without knowing in advance where the files are located. So, I thought of find as the de facto utility to do this... It works as expected, but the ...
0
votes
2answers
65 views

How to search for broken links on the entire local file system of a server?

I have to do this in korn because bash is not installed. This is my script so far but it's not quite working as I expect. cd / find . -xdev -type d > /tmp/dirlist export YOURLIST=`cat ...
0
votes
2answers
267 views

Korn Shell .kshrc

I'm trying to make the UP arrow to get previous command in Korn Shell but I can't find .kshrc file in my $HOME directory. I know it is hidden but even ls -al doesn't show it. What should I do?
0
votes
2answers
2k views

Fastest way to get creation and last modification times of a lot of files

Given a directory a sh pattern which yields a subset of files directly in this directory (like *.log) a sh pattern which can, given a filename, what is the fastest way (in ksh) to obtain for each ...
0
votes
4answers
96 views

Unix find command help

Hi can anybody help me with the following line; find . \( -type d ! -name . -prune \) -o -type f -name "*Log*" Basically it should find directories where files with "Log" in their name are present. ...
0
votes
2answers
137 views

lines identical except for their first word, put the first word in a variable

I have file(sudoers) in which lines can be identical except for the first word in them (different users can execute the same set of commands). I am able to extract such a line using the command: # ...
0
votes
5answers
832 views

Start linux command with “su” and inline variable

I'm trying to create mozilla profile for another user from command line using su. When I'm trying from X, this will work. su myuser -c 'mozilla -CreateProfile newprofile' But my goal is to embed ...
0
votes
1answer
2k views

How to create a new background process in a KSH “while read” loop?

The following test script has a problem. When I add the line (sleep 5 ) & in the script then the "while read" loop does not read all lines from the file, but only prints the first line. But when ...
0
votes
2answers
865 views

How to repeat commands from history in ksh vi-mode

Say I have a hundred commands in my shell's history, and now I'd like to repeat commands 74 through 78. In the emacs mode of bash/ksh/zsh, I would navigate back to command 74 then hit Control-O on ...
0
votes
1answer
74 views

Is There Any Danger in Closing a Parent Xterm Shell with an Active Child?

When I log into my unix servers, I get an xterm window and usually open several more from that initial one. Is there any danger in closing the first window but keeping the children windows open?
0
votes
1answer
13 views

Assign Substr of a string to a variable

I am new to unix script. i am asked to modify a ksh script. it requires i assign a substring of a string to another variable. I tried below and its not working GET_OLDEST_FILE=`ls -ltr ...
0
votes
0answers
81 views

ksh script using if break statements

I have a script file that has the server details like set -A SERVERGRPS SERVERS_CA SERVERS_NY set -A CA ca126 ca546 ca 642 set -A NY ny112 ny113 ny114 now I have to write a another script which ...