Rev 37 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/env bash# =============================================================================# Create# name : Andre Rikkert de Koe date: Apr 2011# descr : filefind# This is a demo of programming in the Bash language.# Its part of a project to implement a program to create a directory# tree similar to the output of the Unix find program.# EUID : Any user who has read access to all the files being searched for.# run : interactive## Changes# name : date:# descr : short description## =============================================================================# =============================================================================# Functions# =============================================================================Usage(){mesg="$1"echo "Usage: $progname directory"echo $mesg}## we need local vars to keep the value when called recursively#traverse(){local directory="$1"local curdir curdir2curdir=$(pwd)cd -- "$directory"curdir2=$(pwd)files=$(ls -a)for file in $filesdopfile=$curdir2/$file # file including pathif [ $file != ".." -a $file != "." ]thenif [ -d "$file" -a ! -L "$file" ]thenecho $pfiletraverse "$file"elseif [ -f $file -o -L $file ]thenecho "$pfile"elseecho "WARNING: Could not process file $pfile"fififidonecd -- "$curdir"}start_traverse(){directory=$1echo $directorytraverse $directory}# =============================================================================# MAIN# =============================================================================progname=$(basename $0)if [ $# -eq 1 ]thendirectory=$1if [ -d $directory ]thenstart_traverse $directoryelseUsage "ERROR: No a directory : $directory"fielseUsage "ERROR: 1 argument expected"fi