ksh

How can you get a variable's value given its name in korn shell?

Is there a way in ksh to get a variable's value when you have been given the name of the variable? For example: #!/usr/bin/ksh var_name=$1 #pretend here that the user passed the string "PATH" echo ${$var_name} #echo value of $PATH -- what do I do here? ...

What is the best (portable and maintanable) Shell Scripting language today?

Hi All, I know this question has kind-a started "religious" wars in past and there might not be one correct answer. But after working with ksh and csh for last 3-4 years and going through the pain of porting from one to another or applying a common piece of logic to multiple versions (read as legacy code), if I am writing a new script, ...

How to capture your username on Box A after you have ssh’d onto Box B?

Hi, Maybe not the best worded question, but hopefully it's a straightforward problem. The scenario is ssh'ing from a personal account on box A to a generic account on box B. The script running on box B needs to capture the personal account name for logging purposes. Is there any way of capturing this, either via ssh itself or some in...

Ksh script: Run bash-like character substitute: ${@/.txt/}

I have a ksh script that has to remain so (some of the programs it runs insist on being ksh). I want to take the input argument "test.txt" and remove the last 4 characters or find and replace the ".txt" with nothing. In bash I would do NewVar=${@/.txt/} This doesn't work in ksh though. How can I get rid of the .txt in ksh? I tried ...

How can I program ksh93 to use bash autocompletion?

In a comment in response to a shell question, user tinkertim said that it was easy to hack ksh to use the bash autocompletion library. I would like nothing better than to use bash autocompletion with AT&T ksh93. How can this be done? ksh93 has a new release several times a year, so I am looking for a solution that does not involve mod...

Detecting interactive shell within ksh ENV script

What's the preferred way to determine if a given ksh invocation is running an interactive shell? I have some commands in an ENV file that I would like to skip for non-interactive ksh invocations (e.g. when executing a shell script). I've seen suggesting ranging from: if [[ $- = *i* ]]; then # do interactive stuff fi ...to not ev...

pushd/popd on ksh?

Is there an equivalent of the bash pushd/popd build in commands for the KSH? For those who don't know what pushd and popd in bash do, here is the description from the man page pushd [-n] [dir] pushd [-n] [+n] [-n] Adds a directory to the top of the directory stack, or rotates the stack, making the new top of ...

Tab Complete with KSH in emacs Mode without bindings

Hi, I'm trying to enable auto complete for the command line in emacs mode. When I try: set -o emacs bind '^I'=complete bind '^I'=complete-list and relog on, I get "bind command not found" error. Is there any other way to tab-autocomplete in emacs mode, i.e. a tab completes to the first difference? If not, how do I install bind...

Extract history from Korn shell

I am not happy about the history file in binary format of the Korn shell. I like to "collect" some of my command lines, many of them actually, and for a long time. I'm talking about years. That doesn't seem easy in Korn because the history file is not plain text so I can't edit it, and a lot of junk is piling up in it. By "junk" I mean ...

Is there any difference between using typeset in ksh to simply setting a variable?

Are the following 2 lines completely equivalent? If not what's the difference? I've seen plently of shellscripts utilize number 1 and was just wondering what it gives you compared with number 2. typeset TARGET="${XMS_HOME}/common/jxb/config/${RUNGROUP}.${ENV}.properties" TARGET="${XMS_HOME}/common/jxb/config/${RUNGROUP}.${ENV}.proper...

How to deal with NFS latency in shell scripts

I'm writing shell scripts where quite regularly some stuff is written to a file, after which an application is executed that reads that file. I find that through our company the network latency differs vastly, so a simple sleep 2 for example will not be robust enough. I tried to write a (configurable) timeout loop like this: waitLoop...

Simple Unix question - Configure

I'm using Solaris 10, ksh. Whenever I do a ./configure, I get the error "ksh: ./configure: not found" When I do a "where configure", nothing is found. How do I "install configure"? ...

How to custom display prompt in KSH to show hostname and current directory?

I'm using Korn Shell on Solaris and currently my PS1 env var is: PS1="${HOSTNAME}:\${PWD} \$ " And the prompt displays: hostname:/full/path/to/current/directory $ However, I'd like it to display: hostname:directory $ In other words, how can I display just the hostname and the name of the current directory, i.e. tmp or ~ or public_h...

Checking if a directory exists on another server in ksh

I am trying to verify if a directory exists prior to moving a file in Korn, using the classic: if [[ -d ${dir} ]]; then scp file else exit 12 fi My Problem: That the directory is on another server, so whenever I check, the script can't find it and therefore fails and exits every time. My Question: Is ther...

Shell documentation (bash, ksh)

is there a tool out there similar to Javadoc or POD for shell scripting? thanks EDIT: I am not looking for existing shell man pages - there is a lot of ksh/bash code we write/support, so I was looking for a nice way to communicate what's happening, whether there is a potential for code reuse, etc. all things Javadocs are good for. ...

Potential Dangers of ALIASing a Unix Command Starting with "."?

I'd like to use alias to make some commands for myself when searching through directories for code files, but I'm a little nervous because they start with ".". Here's some examples: $ alias .cpps="ls -a *.cpp" $ alias .hs="ls -a *.h" Should I be worried about encountering any difficulties? Has anyone else done this? ...

korn Shell script to get files between two dates

Hi, Need to get the files between two given dates. If there are multiple files on one day get the latest of the files for that day. ...

korn shell script to get the most recent file for a given day

HI, I have a list of files from the last 7 days. From this list, if there are multiple files on a certain day, i need to get the latest for that day using korn shell script. Please help! ...

test fails with "argument expected" when comparing "("

Can someone please explain why this command returns an error (on Solaris ksh): if [ "(" = "(" ]; then echo 1;fi; ksh: test: argument expected The same using bash is OK, and echoes "1" as expected Also, using [[ ]] is OK. The problem seems to be the first "(" ...

Find all files in a directory that are not directories themselves.

I am looking for a way to list all the files in a directory excluding directories themselves, and the files in those sub-directories. So if I have: ./test.log ./test2.log ./directory ./directory/file2 I want a command that returns: ./test.log ./test2.log and nothing else. ...