ksh

Shortest command to calculate the sum of a column of output on Unix?

I'm sure there is a quick and easy way to calculate the sum of a column of values on Unix systems (using something like awk or xargs perhaps), but writing a shell script to parse the rows line by line is the only thing that comes to mind at the moment. For example, what's the simplest way to modify the command below to compute and displ...

What would be the simplest way to deal with a text file using JSP?

First and foremost I should acknowledge that I have no experience at all using Java ServerPages, but I'm positive about achieving this task if you guys help me out a bit since it doesn't seem like something difficult for a seasoned JSP programmer. Anyway the thing is, there's an actual running JSP application within a *NIX box which I s...

What would be the right way to declare an array within a script that will be called by cron?

I've written a Korn Shell script that sets an array the following way: set -A fruits Apple Orange Banana Strawberry but when I'm trying to run it from within cron, it raises the following error: Your "cron" job on myhost /myScript.sh produced the following output: myScript.sh: -A: bad option(s) I've tried many crontab syntax vari...

How to warn for the use of unset variables in a korn shell script

Is there any way to throw errors or warnings in a korn shell script to prevent the use of unset variables ? Let's assume I have a temporary folder that I want to remove. TEMP_FILES_DIR='/app/myapp/tmp' rm -Rf $TEMP_FILE_DIR #notice the misspelling How to prevent this kind of mistakes before they actually happen? I know the script sh...

Does pdksh (public domain korn shell) support associative arrays?

I recently ran up against a wall doing some bash shell programming where an associative array would have solved my problems. I googled about features of the Korn shell and learned that it supports associative arrays, so I installed Cygwin's pdksh (public domain korn shell). However, when trying to create an associative array in the pre...

shell script templates

what would be your suggestions for a good bash/ksh script template to use as a standard for all newly created scripts? I usually start (after #! line) with a commented-out header with a filename, synopsis, usage, return values, author(s), changelog and would fit into 80-char lines. all documentation lines I start with double-hash symbo...

Shell script user prompt/input

This is a crude korn shell script that someone else wrote. I don't know much about using shell syntax and I'm not even sure if this is possible. Is there any way for me to run this file and be prompted for the date so that I don't have to manually go into the script and change it each time? For example, I wan to replace the "1/12/09" ...

Awk appears to disconnect my DB2 session when piping

Hello. I'm attempting to run the following command in Korn Shell (ksh): set -A INDEXES `db2 "describe indexes for table ${TABSCHEMA}.${TABNAME} show detail" | awk '{print $1"."$2}'` What I'm attempting to achieve is place a list of the indexes over a particular table into an array which I can later iterate through. The problem is, w...

How do I recursively list all directories at a location, breadth-first?

Breadth-first list is important, here. Also, limiting the depth searched would be nice. $ find . -type d /foo /foo/subfoo /foo/subfoo/subsub /foo/subfoo/subsub/subsubsub /bar /bar/subbar $ find . -type d -depth /foo/subfoo/subsub/subsubsub /foo/subfoo/subsub /foo/subfoo /foo /bar/subbar /bar $ < what goes here? > /foo /bar /foo/subfoo...

Shell script datetime function?

I am running the following script: #!/bin/ksh ./clear_old ./rooms_xls.pl 2/23/09 cd doors ./doors_xls.pl 2/23/09 How can I get the date to be today's date based upon the system/server time? ...

How to keep from duplicating path variable in ksh.

Similar question to How to keep from duplicating path variable in csh. But I don't use csh. PATH=${SOMETHING}:${PATH} How do I remove duplicates from PATH. ...

Select unique or distinct values from a list in UNIX shell script

I have a ksh script that returns a long list of values, newline separated, and I want to see only the unique/distinct values. It is possible to do this? For example, say my output is file suffixes in a directory: tar gz java gz java tar class class I want to see a list like: tar gz java class ...

ksh: how to probe stdin?

I want my ksh script to have different behaviors depending on whether there is something incoming through stdin or not: (1) cat file.txt | ./script.ksh (then do "cat <&0 >./tmp.dat" and process tmp.dat) vs. (2) ./script.ksh (then process $1 which must be a readable regular file) Checking for stdin to see if it is a terminal[ -t 0...

Convert Unix path to DOS path in a Korn shell script

I have a variable that stores a Unix path, for example: typeset unixpath=/foo/bar/ And I have to convert it to a DOS path using Korn shell scripting: dospath=\\foo\\bar\\ ...

if file is a link on LINUX OS

I am trying to check if a symbolic link exists from korn shell script using "-h filename" command.This works good on HP boxes. Not sure what is the correct option for Linux,AIX and Solaris boxes. ...

Can I get the absolute path to the current script in Korn Shell?

Is it possible to find out the full path to the script that is currently executing in Korn shell? i.e. if my script is in /opt/scripts/myscript.ksh, can I programmatically inside that script discover '/opt/scripts/myscript.ksh'? Thanks, ...

How to mkdir only if a dir does not already exist?

I am writing a script to run under the korn shell on AIX. I'd like to use the mkdir command to create a directory. But the directory may already exist, in which case I don't want to do anything. So I want to either test to see that the directory doesn't exist, or suppress the "File exists" error that mkdir throws when it tries to create ...

Coloring directory name in ksh

In my current situation, it is not unusual for me to have several UNIX computers I connect to, as several different users depending on the situation, and to traverse through various directories on the machines doing things. I use ksh through the entire thing. I was fiddling with my prompt recently, and I was able to get it to change som...

Will this redirection ">>& <filename>" work in Korn shell?

I am trying to redirect both STDOUT/STDERR of a UNIX command and append to a log file in a korn shell. rm -rf file1 >>& logfile Will this command work in ksh or is this a typical bash command? What harm would I be causing with above command? ...

disown a process in ksh

The "disown" command works in bash, but not in ksh. If I have started a process in ksh, how can I "disown" it, so I can exit my shell. (I know about nohup, but the process has already started!) ...