*BSD News Article 1837


Return to BSD News archive

Xref: sserve comp.unix.shell:5245 comp.unix.bsd:1872
Newsgroups: comp.unix.shell,comp.unix.bsd
Path: sserve!manuel!munnari.oz.au!uunet!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!hobbes.physics.uiowa.edu!news.uiowa.edu!news.weeg.uiowa.edu!dkeber
From: dkeber@news.weeg.uiowa.edu (David Keber)
Subject: Mysterious error in .logout
Message-ID: <1992Jul7.154630.12118@news.weeg.uiowa.edu>
Organization: University of Iowa, Iowa City, IA, USA
Date: Tue, 7 Jul 1992 15:46:30 GMT
Lines: 109

Machine:  Encore MultiMax running 4.3 BSD UNIX

Background:  I have a directory with a bunch of plain text files, each one
             containing just one of those little doodles people put in
             their signatures or other "ascii art".  I want to pick one of
             those files at random and then cat it out to the screen.

Approach:  Wrote a shell script to create a file in the directory called
           ".contents".  This file is has the number of files in the
           directory on the first line and then the name of each file
           in the directory, one on each line.  A C program then reads
           the .contents file and randomly picks one of the filenames.
           Lastly, just cat the file chosen.

Problem:  This approach works great when run as a shell script.  However,
*******   when the script is saved as ".logout" and you log out...an
          annoying "Ambiguous output redirect" error occurs and the script
          (and consequently the logout) is aborted!

Debugging:  I shortened the .logout to try to see where problem was
            (hence all the "echo" statements).  The way I create the
            .contents file is to redirect ls -1 | wc -l to the file
            then append a redirected ls -1 behind that.  Here is the
            script:

% cat .logout
#! /bin/csh
#
echo ''
echo Account Status:
money
set pictdir="$HOME/misc/picts"
set fname="$pictdir/.contents"
echo "$pictdir"
echo "$fname"
echo "ls -1 $pictdir | wc -l >! $fname # count the number of files in dir."
ls -1 $pictdir | wc -l >! $fname       # count the number of files in dir.
cat $fname
echo "ls -1 $pictdir >> $fname         # list the files in dir."
ls -1 $pictdir >> $fname               # list the files in dir.
cat $fname
cat $pictdir/bill.the.cat


EXAMPLES - Running the file as an ordinary shell script:

% .logout

Account Status:
Remaining:   $5,142.01  Used:      $50.59  As of:  4.47.39 AM 07 JUL 92
/usr0/dkeber/misc/picts
/usr0/dkeber/misc/picts/.contents
ls -1 /usr0/dkeber/misc/picts | wc -l >! /usr0/dkeber/misc/picts/.contents # count the number of files in dir.
      21
ls -1 /usr0/dkeber/misc/picts >> /usr0/dkeber/misc/picts/.contents         # list the files in dir.
      21
Botany_Bay
Galileo7
Gym.Klingon
Gym.NCC-1701
Klingon
Klingon.BOP
Macintosh
NCC-1701
NCC-1701.bot
NCC-1701.front
NCC-1701.top
NCC-1864
Starfleet.Arrow
acdc.logo
bill.the.cat
flash.symbol
hockey.court
lightning
porsche
simpsons
unknown

               _   /|  
 Ack Thippfft! \'o.O`  
               =(___)= 
                  U    

* * * * * * 
So far, everything worked as it should.  Now try doing an actual logout:

% logout
 
Account Status:
Remaining:   $5,142.01  Used:      $50.59  As of:  4.47.39 AM 07 JUL 92
/usr0/dkeber/misc/picts
/usr0/dkeber/misc/picts/.contents
ls -1 /usr0/dkeber/misc/picts | wc -l >! /usr0/dkeber/misc/picts/.contents # cou
nt the number of files in dir.
      21
ls -1 /usr0/dkeber/misc/picts >> /usr0/dkeber/misc/picts/.contents         # lis
t the files in dir.
Ambiguous output redirect.
%

* * * * * * 
It doesn't like the append step?!!?  But why not?  It works fine when you're
running it as an ordinary shell script!  Is there something weird that goes
on when your logging out that doesn't allow you to do appends?  It doesn't
make sense, the previous redirection worked fine!  And why the error
"Ambiguous output redirect."  What is ambiguous about it?  Is this really
what the problem is?  HELP!  Any advice/solutions would be much appreciated!

Reply-To:  david-keber@uiowa.edu