ksh

Shell scripting input redirection oddities

Can anyone explain this behavior? Running: #!/bin/shecho "hello world" | read var1 var2echo $var1echo $var2 results in nothing being ouput, while: #!/bin/shecho "hello world" > test.fileread var1 var2 < test.fileecho $var1echo $var2 produces the expected output: helloworld Shouldn't the pipe do in one step what the redirection to t...

Why shouldn't I "bet the future of the company" on shell scripts?

I was looking at http://tldp.org/LDP/abs/html/why-shell.html and was struck by: When not to use shell scripts ... Mission-critical applications upon which you are betting the future of the company Why not? ...

Why doesn't **find** find anything?

I'm looking for shell scripts files installed on my system, but find doesn't work: $ find /usr -name *.sh But I know there are a ton of scripts out there. For instance: $ ls /usr/local/lib/*.sh /usr/local/lib/tclConfig.sh /usr/local/lib/tkConfig.sh Why doesn't find work? ...

Is there any way to prevent find from digging down recursively into subdirectories?

When I do: $ find / It searches the entire system. How do I prevent that? (This question comes from an "answer" to another question.) ...

Why doesn't **sort** sort the same on every machine?

Using the same sort command with the same input produces different results on different machines. How do I fix that? ...

How do you use ssh in a shell script?

When I try to use an ssh command in a shell script, the command just sits there. Do you have an example of how to use ssh in a shell script? ...

Converting scripts from ksh to bash.

I have some ksh scripts which I'd like to convert to run with bash instead. Are there any useful on-line resources for this? I'm really looking for a list of differences between the two shells and any gotchas I might encounter, although all information is welcome :-) ...

What is the lowest-cost, cross-platform approach to parse XML using ksh?

Need to parse some basic XML (one root element, 3-4 subelements, 1-3 attributes each) from a ksh script (ideally stick to ksh, given the script already exists and it's just trying to read some extra configuration created in XML by another program). I know I can use sed and do pattern matching, but it's not foolproof given that the input...

How can I check for a file size and add that result in an Excel spreadsheet in Perl?

Currently I monitoring a particular file with a simple shell one-liner: filesize=$(ls -lah somefile | awk '{print $5}') I'm aware that Perl has some nice modules to deal with Excel files so the idea is to, let's say, run that check daily, perhaps with cron, and write the result on a spreadsheet for further statistical use. ...

How to overcome an incompatibility between the ksh on Linux vs. that installed on AIX/Solaris/HPUX?

I am involved in the process of porting a system containing several hundreds of ksh scripts from AIX, Solaris and HPUX to Linux. I have come across the following difference in the way ksh behaves on the two systems: #!/bin/ksh flag=false echo "a\nb" | while read x do flag=true done echo "flag = ${flag}" exit 0 On AIX, Solaris and ...

Bash or Ksh ?

I'm not new to *nix, however lately I have been spending a lot of time at the prompt to do my development for my job. My question is what are the advantages of using Korn Shell or Bash Shell? Where are the pitfalls of using one over the other? Looking to understand from the perspective of a user, rather than purely scripting. ...

Best practises for holding passwords in shell / Perl scripts?

I've recently had to dust off my Perl and shell script skills to help out some colleagues. The colleagues in question have been tasked with providing some reports from an internal application with a large Oracle database backend, and they simply don't have the skills to do this. While some might questions whether I have those skills eith...

How to autocomplete at the Korn shell command line with the vi editor

In the Korn shell on AIX UNIX Version 5.3 with the editor mode set to vi using: set -o vi What are the key-strokes at the shell command line to autocomplete a file or directory name ? ...

REDUX: How to overcome an incompatibility between the ksh on Linux vs. that installed on AIX/Solaris/HPUX?

I have uncovered another problem in the effort that we are making to port several hundreds of ksh scripts from AIX, Solaris and HPUX to Linux. See here for the previous problem. This code: #!/bin/ksh if [ -a k* ]; then echo "Oh yeah!" else echo "No way!" fi exit 0 (when run in a directory with several files whose name starts ...

Korn Shell code to send attachments with mailx and uuencode?

I need to attach a file with mailx but at the moment I'm not having a lot of success. Here's my code: subject="Something happened" to="[email protected]" body="Attachment Test" attachment=/path/to/somefile.csv uuencode $attachment | mailx -s "$subject" "$to" << EOF The message is ready to be sent with the following file or link a...

Korn shell wraparound

Okay, I'm sure this is simple but it is driving me nuts. I recently went to work on a program where I've had to step back in time a bit and use Redhat 9. When I'm typing on the command line from a standard xterm running Korn shell, when I reach the end of the line the screen slides to the right (cutting off the left side of my command) i...

KSH scripting: how to split on ',' when values have escaped commas? [solved]

I try to write KSH script for processing a file consisting of name-value pairs, several of them on each line. Format is: NAME1 VALUE1,NAME2 VALUE2,NAME3 VALUE3, etc Suppose I write: read l IFS="," set -A nvls $l echo "$nvls[2]" This will give me second name-value pair, nice and easy. Now, suppose that the task is extended so that ...

How do I print a field from a pipe-separated file?

I have a file with fields separated by pipe characters and I want to print only the second field. This attempt fails: $ cat file | awk -F| '{print $2}' awk: syntax error near line 1 awk: bailing out near line 1 bash: {print $2}: command not found Is there a way to do this? ...

How do I calculate the previous business day in ksh shell script ?

What is the most elegant way to calculate the previous business day in shell ksh script ? What I got until now is : #!/bin/ksh set -x DAY_DIFF=1 case `date '+%a'` in "Sun") DAY_DIFF=2 ;; "Mon") DAY_DIFF=3 ;; esac PREV_DT=`perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time()-${DAY_DIFF}*24*60*60...

What's the best way of executing tasks in parallel in Ksh and Perl?

I have this large C++ project that I need to build on a platform that does not have a parallel make (like make -j on Linux). The server has 6 CPU's and I want to do a parallel build manually. I can generate a task list like this for about 300 object files. I use the Makefile for the dependency checks and incremental build: make -f Mak...