#!/bin/bash: list all users. PASSWORD_FILE=/etc/passwd n=1 for name in $(awk 'BEGIN{FS=":"}{print $1}' < "$PASSWORD_FILE" ) do echo "USER #$n = $name" let "n+=1" done exit $?
#!/bin/bash # bin-grep.sh: locates matching strings in a binary file. E_BADARGS=65 E_NOFILE=66 if [ $# -ne 2 ] then echo "Usage: `basename $0` search_string filename" exit $E_BADARGS fi if [ ! -f "$2" ] then echo "File \"$2\" does not exit." exit $E_NOFILE fi IFS=$'\012' for word in $( strings "$2" | grep "$1" ) # the "strings" command lists strings in binary files. # output then piped to "grep", which tests for desired string. do echo $word done exit 0