What's up with pdksh-5.2.3?

What's up with pdksh-5.2.3?

Post by Albert E. Wha » Tue, 07 May 1996 04:00:00



I don't understand why the for command in the pdksh-5.2.3 utility
doesn't act the same as the standard ksh shell.

This simple shell script:

#!/bin/ksh -x

cd /usr/adm
for cn in "messages debug secure lastlog wtmp utmp maillog POPlog
xferlog spoolerr";
do
    echo $cn;
    ls -l /usr/adm/${cn};
    cp $cn "$cn.`date "+%y%m%d"`";
done

Produces this output:

+ cd /usr/adm
+ echo messages debug secure lastlog wtmp utmp maillog POPlog xferlog
spoolerr
messages debug secure lastlog wtmp utmp maillog POPlog xferlog
spoolerr
+ ls -l /usr/adm/messages debug secure lastlog wtmp utmp maillog
POPlog xferlog spoo
lerr
-rw-rw-r--   1 root     root      3623724 May  5 22:32
/usr/adm/messages
-rw-r--r--   1 root     root      1019386 May  4 13:15 POPlog
-rw-r-----   1 root     root      8154400 May  5 22:30 debug
-rw-r--r--   1 root     root        14496 May  5 21:38 lastlog
-rw-r--r--   1 root     root        25197 May  5 13:10 maillog
-rw-r--r--   1 root     root        44082 May  5 21:38 secure
-rw-r--r--   1 root     root        19216 Apr 24 00:43 spoolerr
-rw-r--r--   1 root     root         5432 May  5 21:38 utmp
-rw-r--r--   1 root     root       355768 May  5 21:38 wtmp
-rw-r-----   1 root     root        34986 May  4 16:11 xferlog
+ date +%y%m%d
+ cp messages debug secure lastlog wtmp utmp maillog POPlog xferlog
spoolerr message
s debug secure lastlog wtmp utmp maillog POPlog xferlog
spoolerr.960505
cp: when copying multiple files, last argument must be a directory
Try `cp --help' for more information.

I don't understand why the script scans through all of the variables
before executing each of the commands.  What did I do wrong here?

This script is intended to copy various files to a similar filename
with a date extension which I then intend on compressing and keeping
for 3 months.  Unfortunately this script presents all of the variables
to each command in succession before it executes each command.

Any advice?

 
 
 

What's up with pdksh-5.2.3?

Post by Larry Daffn » Tue, 07 May 1996 04:00:00



Quote:>I don't understand why the for command in the pdksh-5.2.3 utility
>doesn't act the same as the standard ksh shell.

>#!/bin/ksh -x

>cd /usr/adm
>for cn in "messages debug secure lastlog wtmp utmp maillog POPlog
>xferlog spoolerr";
>do
>    echo $cn;
>    ls -l /usr/adm/${cn};
>    cp $cn "$cn.`date "+%y%m%d"`";
>done

>I don't understand why the script scans through all of the variables
>before executing each of the commands.  What did I do wrong here?

Try removing the double quotes from the for line. IE:
for cn in messages debug secure lastlog wtmp utmp maillog POPlog \
        xferlog spoolerr;
do
        echo $cn
        ls -l /usr/adm/${cn}
        cp $cn $cn.`date +%y%m%d`
done

That should do it for you - the double quotes escape the spaces in
your example and turn all the args into 1.

HTH

-Larry

--
  Larry Daffner        |  Linux: Unleash the workstation in your PC!

Never underestimate the bandwidth of a station wagon full of mag tapes
        -- Dennis Ritchie

 
 
 

What's up with pdksh-5.2.3?

Post by Joris Zwa » Wed, 08 May 1996 04:00:00




Quote:>I don't understand why the for command in the pdksh-5.2.3 utility
>doesn't act the same as the standard ksh shell.
>This simple shell script:
>for cn in "messages debug secure lastlog wtmp utmp maillog POPlog
           ^
>xferlog spoolerr";

                 ^

[snip]

Quote:>I don't understand why the script scans through all of the variables
>before executing each of the commands.  What did I do wrong here?

You quoted the list, making the for command see the whole list as one
parameter. I don't know whether it is standard behaviour for the standard
ksh to act like you intended if the list is quoted, but since bash acts
exactly the same way it probably isn't. If you do:

$ for a in "a b c"

Quote:> do
> echo $a
> done

the result is:

a b c

indicating that the loop was only executed once. If you remove the quotes,
you get

a
b
c

which is probably what you intended. pdksh has compatibility problems, but
this is not one of them.

Success with your script, Joris

------------If debugging is the art of removing bugs, then programming must
Joris S. Zwart           be the art of putting them in - Edsger W. Dijkstra

(PGP public key available by finger)----------------#include <disclaimer.h>

 
 
 

1. 2.3 -> 2.7 via Dial-up (Re: CVS over 'dropping' dial-ups)

You are better off borrowing/buying/stealing a CD and loading a fresh 2.7
install.
From what I've heard, there are issues with upgrading via CVS.  Plus, it's
_SLOW_.
Trust me. If you don't have the cash (US $30, I believe) you could probably
ask
somebody to copy their 2.7 CD for you (hint,hint).  Of course, buying the CD
makes
OBSD 2.8 and higher a possibility, which is a Good Thing.

Good luck.

2. Can't install 112438-01

3. Shape Ups,Men's Shape Ups,Men's Skechers Shape Ups - new styles!

4. swap space

5. Can't compile Pdksh-5.1.3.

6. 2.5.40 panic in uhci-hcd

7. ksh.1 for pdksh v5.2.3

8. executable and library have different versions

9. Sol 2.3, Random lock-ups

10. Sol 2.3: 'df -d /' and 'du' discrepancy on root partition!

11. UPS debugger Solaris 2.3

12. ups debugger on solaris 2.3

13. 'make' and 'cc' on Solaris 2.3