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

Re: [cobalt-users] Re: Shell script



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> #!/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...

- -- 
Bruce Timberlake

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+MyHKvLA2hUZ9kgwRAm+eAJ9fKuK7C9NoOct7rDxXiu7E7kDCTgCeLlAe
pbpVSWnWmLncsSAv06izaJY=
=GLbl
-----END PGP SIGNATURE-----