Читаем UNIX — универсальная среда программирования полностью

cd . # place holder for /usr/news

for i in `ls -t * $HOME/.news_time`

do

 case $i in

 */.news_time) break ;;

 *) echo news: $i

 esac

done

touch $HOME/.news_time

3.8.31 news2

# news: print news files, version 2


HOME=. # debugging only

cd . # place holder for /usr/news

IFS='

' # just a newline

for i in `ls -t * $HOME/.news_time 2>&1`

do

case $i in

*' not found') ;;

*/.news_time) break ;;

*) echo news: $i ;;

esac

done

touch $HOME/.news_time

3.8.32 news3

# news: print news files, final version


PATH=/bin:/usr/bin

IFS='

' # just a newline

cd /usr/news


for i in `ls -t * $HOME/.news_time 2>&1`

do

 IFS=' '

 case $i in

 *' not found') ;;

 */.news_time) break ;;

 *) set X`ls -l $i`

  echo "

$i: ($3) $5 $6 $7

"

  cat $i

 esac

done

touch $HOME/.news_time

3.8.33 nohup

trap "" 1 15

if test -t 2>&1

then

 echo "Sending output to 'nohup.out'"

 exec nice -5 $* >>nohup.out 2>&1

else

 exec nice -5 $* 2>&1

fi

3.8.34 older

# older f: list files older than f

ls -tr | sed '/^'$!'$/q'

3.8.35 overwrite1

# overwrite: copy standard input to output after EOF

# version 1. BUG here


PATH=/bin:/usr/bin


case $# in

1) ;;

*) echo 'Usage: overwrite file' 1>&2; exit 2

esac


new=/tmp/overwr.$$

trap 'rm -f $new; exit 1' 1 2 15


cat >$new # collect the input

cp $new $1 # overwrite the input file

rm -f $new

3.8.36 overwrite2

# overwrite: copy standard input to output after EOF

# version 2. BUG here too


PATH=/bin:/usr/bin


case $# in

1) ;;

*) echo 'Usage: overwrite file' 1>&2; exit 2

esac


new=/tmp/overwr1.$$

old=/tmp/overwr2.$$

trap 'rm -f $new $old; exit 1' 1 2 15


cat >$new # collect the input

cp $1 $old # save original file


trap '' 1 2 15 # we are committed; ignore signals

cp $new $1 # overwrite the input file


rm -f $new $old

3.8.37 overwrite3

# overwrite: copy standard input to output after EOF

# final version


opath=$PATH

PATH=/bin:/usr/bin


case $# in

0|1) echo 'Usage: overwrite file cmd [args]' 1>&2; exit 2

esac


file=$1; shift

new=/tmp/overwr1.$$; old=/tmp/overwr2.$$

trap 'rm -f $new $old; exit 1' 1 2 15 # clean up files


if PATH=$opath >$new # collect input

then

 cp $file $old # save original file

 trap '' 1 2 15 # we are committed; ignore signals

 cp $new $file

else

 echo "overwrite: $1 failed, $file unchanged" 1>&2

 exit 1

fi

rm -f $new $old

3.8.38 p1.c

/* p: print input in chunks (version 1) */


#include

#define PAGESIZE 22

char *progname; /* program name for error message */


main(argc, argv)

 int argc;

 char *argv[];

{

 int i;

 FILE *fp, *efopen();


 progname = argv[0];

 if (argc == 1)

  print(stdin, PAGESIZE);

 else

  for (i = 1; i < argc; i++) {

   fp = efopen(argv[i], "r");

   print(fp, PAGESIZE);

   fclose(fp);

  }

  exit(0);

}


Перейти на страницу:
Нет соединения с сервером, попробуйте зайти чуть позже