|
Home > Archive > Unix Programming > December 2007 > 0403-057 Syntax error: directory is not expected.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
0403-057 Syntax error: directory is not expected.
|
|
| Rivanor Soares (web_knows) 2007-12-18, 1:33 pm |
| Hi all,
Sorry if I'm reaching anyone cross-posting.
I started writing the code[2] for ksh for the pseudo-code[1] below,
but found a few "issues". Got this:
./cp2notes.sh[17]: 0403-057 Syntax error at line 19 : `$NTSDIR' is
not expected.
Any clues on that?
[1] - pseudo-code
'find' the list of .txt files in the /home/casa/dir1 directory that
were modified/created since the last run of this script;
(example find command -> find /home/casa/dir1 -newer /home/casa/dir1/
lastrun -type f -exec ls *.txt {} \\;)
While .txt files remain on the list;
Get a .txt file name;
If there is a like named .txt file in the /home/casa/dir2/
directory Then
Delete the /home/casa/dir2 .txt file;
Copy the /home/casa/dir1 .txt file to the /home/casa/dir2
directory;
Else
Copy the /home/casa/dir1 .txt file to the /home/casa/dir2
directory;
Endif
If there is a like named .ft directory in the /home/casa/dir2/
directory Then
Delete (recursively) the /home/casa/dir2 .ft directory;
Endif
Endwhile
# need to delete .txt/.ft that are in the directory 2 but are not in
the directory 1
'find' .txt files that are in /home/casa/dir2 but are not in /home/
casa/dir1
While .txt file remain on the list;
Get a .txt file name;
Delete the /home/casa/dir2 .txt file;
If there is a like named .ft directory in the /home/casa/dir2/
directory Then
Delete (recursively) the /home/casa/dir2 .ft directory;
Endif
Endwhile
Touch /home/casa/dir1/lastrun file;
[2] - code (written so far)
+8 PIDFILE=/home/casa/lastrun
+9 DATE="`date +"%b%d%Y-%H%M"`"
+10 LOG=/home/casa/txt.log
+11 EPBSDIR=/home/casa/dir1
+12 NTSDIR=/home/casa/dir2
+13 NWFILES="`find $EPBSDIR -newer $PIDFILE -type f -name *.txt`"
+15 #PCKFL=${NWFILES%%\n}
+16
+17 while [[ -n $NWFILES ]]; do
+18 for list in $NWFILES; do
+19 if [[ -n find $NTSDIR -name $list -type f ]];
then
+20 rm $NTSDIR/`cut -f5 -d"/" $files`
+21 cp $files $NTSDIR
+22 else
+23 cp $files $NTSDIR
+24 fi
+25 if [[ -n find $NTSDIR -name $list.ft -type
d ]]; then
+26 rm -R $NTSDIR/`cut -f5 -d"/"
$files`.ft
+27 fi
+28 done
+29 done
+30
+31 #find $NTSDIR -name *.nsf ! $EPBSDIR
+32
+33 touch $PIDFILE
| |
| fjblurt@yahoo.com 2007-12-18, 7:23 pm |
| On Dec 18, 10:43 am, "Rivanor Soares (web_knows)" <riva...@gmail.com>
wrote:
> Hi all,
>
> Sorry if I'm reaching anyone cross-posting.
>
> I started writing the code[2] for ksh for the pseudo-code[1] below,
> but found a few "issues". Got this:
>
> ./cp2notes.sh[17]: 0403-057 Syntax error at line 19 : `$NTSDIR' is
> not expected.
>
> Any clues on that?
[...]
> +19 if [[ -n find $NTSDIR -name $list -type f ]];
> then
Do you perhaps mean
if [[ -n `find $NTSDIR -name $list -type f` ]];
?
| |
| Rivanor Soares (web_knows) 2007-12-19, 7:32 am |
| On Dec 18, 8:31 pm, fjbl...@yahoo.com wrote:
> On Dec 18, 10:43 am, "Rivanor Soares (web_knows)" <riva...@gmail.com>
> wrote:
>
>
>
>
>
> [...]
>
> Do you perhaps mean
>
> if [[ -n `find $NTSDIR -name $list -type f` ]];
>
> ?
Yes, correct. I've fixed that already, thanks.
Also, I heard this from another group (which sounds good to me, didn't
have the chance to test it yet):
<quote>
" Why the while loop? It will never end.
You certainly want
if [[ -n $NWFILES ]]; then
....
....
fi
and you can maybe omit the if .. fi clause,
because the for will run zero times on an empty list. "
</quote>
and this
<quote>
" You maybe want
shortfnam=${files##*/}
if [[ -f "$NTSDIR/$shortfnam" ]]; then
rm "$NTSDIR/$shortfnam"
fi
cp "$files" "$NTSDIR"
Maybe you can omit the if .. fi
because cp will overwrite an existing file.
The entire section could be written as:
(
# get short filenames by cd'ing and run find on '.'
cd "$EPSBDIR" &&
find . -newer "$PIDFILE" -type f -name *.txt
) |
while read -r shortfnam
do
cp "$EPSBDIR/$shortfnam" "$NTSDIR"
shortdirnam=${shortfnam%%.txt}.ft
rm -Rf "$NTSDIR/$shortdirnam"
done "
</quote>
Cheers,
-- web_knows
|
|
|
|
|