[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cobalt-users] Re: Shell script



INRE Re: [cobalt-users] Re: Shell script:
> > #!/bin/bash
> > for VARIABLE in "*"
> > do
> > echo $VARIABLE
> > done
> > ---
> >
> > But doesn't that give me ALL the stuff in VARIABLE?
> > I *ONLY* want the FIRST file to show up, I don't care about 2nd,
> > 3rd, etc etc...
> Ah... sorry, didn't understand.
> So you just need a variable which contains the first filename in the
> directory?  You have to kind of hack it to first grab all the info,
> then stop after just the first...
> #!/bin/bash
> stop=0
> for f in `ls -1`
> do
>         echo $f
>         stop=$(($stop+1))
>         if [ "$stop" -gt 0 ]
>         then
>                 break
>         fi
> done
> exit 0
> Again, this won't grab all files which start with a '.' -- you'd need
> to change
> for f in `ls -1`
> to
> for f in `ls -1a`
> but then it would always die after printing
> You'd have to hack it more -- do 2 loops without echoing/processing,
> then grab/use the 3rd entry...

This could really roll on....
How about 
      "ls -l | head -1" 
or if you are interested in dot files 
  "ls -la | head -1"
or to get back to your original
VARIABLE=`ls -l | head -1`
echo $VARIABLE
_BUT_ this is going to give you something like:
-rw-r--r--   1 root     sys            0 Nov  9  1999 /etc/motd
and not "just" the name....

-- 
Larry Smith
SysAd ECSIS.NET
sysad@xxxxxxxxx