* [9fans] rewriting scripts for rc
@ 2002-08-20 23:18 Andrey S. Kukhar
2002-08-21 12:20 ` Christian Grothaus
0 siblings, 1 reply; 2+ messages in thread
From: Andrey S. Kukhar @ 2002-08-20 23:18 UTC (permalink / raw)
To: 9fans
[-- Attachment #1: Type: text/plain, Size: 88 bytes --]
folks, can you help me with rewriting a few Bourne shell scripts for rc
thanks,
-ask
[-- Attachment #2.1: Type: text/plain, Size: 338 bytes --]
The following attachment had content that we can't
prove to be harmless. To avoid possible automatic
execution, we changed the content headers.
The original header was:
Content-Type: application/x-shellscript;
charset="koi8-r";
name="nom"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="nom"
[-- Attachment #2.2: nom.suspect --]
[-- Type: application/octet-stream, Size: 1190 bytes --]
#! /bin/sh
#
### nom - return names of non-matching files from current directory
### Usage: nom files (example: lpr `nom *.ms`)
##
## nom TAKES FILENAMES (USUALLY, EXPANDED BY THE SHELL) FROM ITS COMMANDLINE.
## IT OUTPUTS ALL FILENAMES IN THE CURRENT DIRECTORY THAT *DON'T* MATCH.
## NOTE: nom DOESN'T KNOW ABOUT FILES WHOSE NAMES BEGIN WITH "."
##
## EXAMPLES:
## TO GET THE NAMES OF ALL FILES THAT *DON'T* END WITH ".ms":
## % nom *.ms
## TO EDIT ALL FILES WHOSE NAMES DON'T HAVE ANY LOWER-CASE LETTERS:
## % vi `nom *[a-z]*`
## TO COPY ALL FILES TO A DIRECTORY NAMED Backup (EXCEPT Backup ITSELF):
## % cp `nom Backup` Backup
temp=/tmp/NOM$$
stat=1 # ERROR EXIT STATUS (SET TO 0 BEFORE NORMAL EXIT)
trap 'rm -f $temp; exit $stat' 0 1 2 15
# MUST HAVE AT LEAST ONE ARGUMENT, AND ALL HAVE TO BE IN CURRENT DIRECTORY:
case "$*" in
"") echo Usage: `basename $0` pattern 1>&2; exit ;;
*/*) echo "`basename $0` quitting: I can't handle '/'s." 1>&2; exit ;;
esac
# GET FILENAMES WE DON'T WANT TO MATCH; REPLACE BLANKS WITH NEWLINES:
echo "$*" | tr ' ' '\012' | sort > $temp
# COMPARE TO CURRENT DIRECTORY (-1 = ONE NAME PER LINE); OUTPUT NAMES WE WANT:
ls -1 | comm -23 - $temp
stat=0
[-- Attachment #3.1: Type: text/plain, Size: 350 bytes --]
The following attachment had content that we can't
prove to be harmless. To avoid possible automatic
execution, we changed the content headers.
The original header was:
Content-Type: application/x-shellscript;
charset="koi8-r";
name="cal_today"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="cal_today"
[-- Attachment #3.2: cal_today.suspect --]
[-- Type: application/octet-stream, Size: 413 bytes --]
#!/bin/sh
#
# cal_today - if user doesn't give an argument, put > < around today's
# date on this month's calendar
case $# in
0) set x `date` # Get the current day of the month into $4
/usr/bin/cal |
# Put > < around $4 (shell expands $4 inside the doublequotes)
sed -e 's/^/ /' -e "s/ $4$/>$4</" -e "s/ $4 />$4</"
;;
# If arguments are given, just run the normal cal
*) /usr/bin/cal "$@" ;;
esac
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [9fans] rewriting scripts for rc
2002-08-20 23:18 [9fans] rewriting scripts for rc Andrey S. Kukhar
@ 2002-08-21 12:20 ` Christian Grothaus
0 siblings, 0 replies; 2+ messages in thread
From: Christian Grothaus @ 2002-08-21 12:20 UTC (permalink / raw)
To: 9fans
Andrey S. Kukhar <plan9@kp.km.ua> wrote:
> [-- text/plain, encoding 8bit, 4 lines --]
> folks, can you help me with rewriting a few Bourne shell scripts for rc
> thanks,
> -ask
> [-- application/x-shellscript, encoding base64, 22 lines, name: nom --]
> [-- application/x-shellscript, encoding base64, 9 lines, name: cal_today --]
Hello Andrey,
you probably got already some solutions. Here are mine
(not testet intensively).
Hope they work!
Christian
--- cal_today -------------------------8<--------------------------------
#!/bin/rc
switch ($#*) {
case 0;
*=`{date}
cal | sed -e 's/^/ /' -e 's/ '^$3^'$/>'^$3^'</' \
-e 's/ '^$3^' />'^$3^'</'
case *;
cal $*
}
--- nom -------------------------------->8-------------------------------
#!/bin/rc
temp=/tmp/NOM$pid
stat=1
fn sigexit sigint sighup sigterm {
rm -f $temp
exit $stat
}
switch ($*) {
case '';
echo Usage: `{basename $0} pattern >[1=2]
exit
case */*;
echo `{basename $0} 'quitting: I can''t handle /s.' >[1=2]
exit
}
echo $* | tr ' ' '\012' | sort > $temp
ls | comm -23 - $temp
stat=0
--- nom (without using a temporary file) --------------------------------
#!/bin/rc
switch ($*) {
case '';
echo Usage: `{basename $0} pattern >[1=2]
exit
case */*;
echo `{basename $0} 'quitting: I can''t handle /s.' >[1=2]
exit
}
comm -23 <{ls} <{echo $* | tr ' ' '\012' | sort}
--------------------------------------->8--------------------------------
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-08-21 12:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-20 23:18 [9fans] rewriting scripts for rc Andrey S. Kukhar
2002-08-21 12:20 ` Christian Grothaus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).