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?