Искусство программирования на языке сценариев командной оболочки




Программирование на языке сценариев командной оболочки - стр. 325


Followed by an access indicator Haven't tested this one, it may be the eleventh character or it may generate another field ' ' No alternate access '+' Alternate access LSfieldsDoc

ListDirectory() { local -a T local -i of=0 # Default return in variable # OLD_IFS=$IFS # Using BASH default ' \t\n'

case "$#" in 3) case "$1" in -of) of=1 ; shift ;; * ) return 1 ;; esac ;; 2) : ;; # Poor man's "continue" *) return 1 ;; esac

# NOTE: the (ls) command is NOT quoted (") T=( $(ls --inode --ignore-backups --almost-all --directory \ --full-time --color=none --time=status --sort=none \ --format=long $1) )

case $of in # Assign T back to the array whose name was passed as $2 0) eval $2=\( \"\$\{T\[@\]\}\" \) ;; # Write T into filename passed as $2 1) echo "${T[@]}" > "$2" ;; esac return 0 }

# # # # # Is that string a legal number? # # # # # # # IsNumber "Var" # # # # # There has to be a better way, sigh...

IsNumber() { local -i int if [ $# -eq 0 ] then return 1 else (let int=$1) 2>/dev/null return $? # Exit status of the let thread fi }

# # # # # Index Filesystem Directory Information # # # # # # # IndexList "Field-Array-Name" "Index-Array-Name" # or # IndexList -if Field-Array-Filename Index-Array-Name # IndexList -of Field-Array-Name Index-Array-Filename # IndexList -if -of Field-Array-Filename Index-Array-Filename # # # # #

: << IndexListDoc Walk an array of directory fields produced by ListDirectory

Having suppressed the line breaks in an otherwise line oriented report, build an index to the array element which starts each line.

Each line gets two index entries, the first element of each line (inode) and the element that holds the pathname of the file.

The first index entry pair (Line-Number==0) are informational: Index-Array-Name[0] : Number of "Lines" indexed Index-Array-Name[1] : "Current Line" pointer into Index-Array-Name

The following index pairs (if any) hold element indexes into the Field-Array-Name per: Index-Array-Name[Line-Number * 2] : The "inode" field element.


Содержание  Назад  Вперед