[EMAIL PROTECTED] wrote:
> Hi,
>         I didn't post a "why, what for" question
>         for awhile...
> 
>         Anyway, could somebody explain what pushd
>         and popd functions, I didn't really
>         understand what stack ( tcsh man page ).
>         I also saw these functions in a couple of PERL
>         scripts, but I couldn't figure out what
>         they did.

Hi!

It's REALLY usefull functions, especially for various scripts.
I don't want to explain how to use it, but i supply my small script that
use this functions for looking into pointed directory and type all files
it found.
============ cut here = my name for it "list_dir" ===========
#!/bin/bash

proc_dir() {
    cur_dir=`pwd`
#    echo Enter dir $cur_dir...
    for i in $cur_dir/* ; do 
#       echo Found $i.... What is it...
        if [ -d $i ] ; then
#           echo It is a directory... 
            pushd $i>/dev/null
#           Wow! Recursive!!!!!!
            proc_dir $i
            popd >/dev/null
        else
            echo $i
        fi
    done
}

# Checking parameter... If none, use current dir...
if [ "$1" != "" ]; then
    if [ -d $1 ] ; then
        cur_dir=$1
    else
        echo $0: $1 does not exist...
        exit 1
    fi
else
    cur_dir=`pwd`
fi

cd $1
if [ $? != 0 ] ; then
    echo $0: $1 does not exist...
    exit 1
fi

pushd $cur_dir >/dev/null
proc_dir $1
popd>/dev/null
============ cut here ==================

It may be used for checking files for changing checksums, permissions or
as alternative for ls, for example for building a list of files in ftp
archive...

Enjoy!

Sergey.


-- 
  PLEASE read the Red Hat FAQ, Tips, Errata and the MAILING LIST ARCHIVES!
http://www.redhat.com/RedHat-FAQ /RedHat-Errata /RedHat-Tips /mailing-lists
         To unsubscribe: mail [EMAIL PROTECTED] with 
                       "unsubscribe" as the Subject.

Reply via email to