Linux, Unix, /etc

Danger Will Robinson! You are now entering a condescending Unix user zone!
Sponsored links (requires javascript):

Scripts: Miscellaneous Handy Things

ascii-series: produce a series of digits down to 1

 
#!/bin/sh
#ascii-series: produce a series of digits from 1, given an upper limit
#note: chr was part of /rdb; but this works without it, anyway!
PATH=/bin:/usr/bin:/usr/local/bin:/usr/local/rdb/bin
progname=`basename $0`
case $# in
    0) 1>&2 echo $progname: usage $progname limit ; exit 1;;
esac

index=$1
while [ "0$index" -gt 0 ]
do
    echo $index
#    chr $index
    index=`expr "$index" - 1`
done


series: produce a series of digits from 1 up to a given upper limit

 
#!/bin/sh
#series: produce a series of digits from 1, given an upper limit
PATH=/bin:/usr/bin:/usr/local/bin
progname=`basename $0`
case $# in
    0) 1>&2 echo $progname: usage $progname limit; exit 1 ;;
esac

count=$1

index=1
while [ "0$index" -le $count ]
do
    echo $index
    index=`expr "$index" + 1`
done


title: sets the title of an xterm window

This also works with rxvt, and indeed any vt100-compatible. A screen session, for instance.

#!/bin/sh
printf "\033]0;$1\007"


sound.volume: change the volume on the soundcard

#!/bin/sh
#sound.volume: change the volume on the soundcard
case $1 in
    "") 2>&1 echo "sound.volume: need volume level; bailing out"; exit 1 ;;
esac
/usr/local/bin/mixer -master=$1,$1 -dsp=$1,$1 -mic=0,0 -line=0,0

mixer(1) is a litle program I found somehwere to do this. As the man page says, "mixer is great for scripts!". The author is Volodya Dergachev, if you want to do a google search for it. Obviously, one out of dsp, mic or line must have values for channels left and right greater than 0! I turn off mic and line with 0 to avoid possible interference. Mixer also has args for treble and bass: it's often useful to turn the bass up if you're listening through headphones jacked into the soundcard. sound.volume is a bit of a handful to type, so I have an alias "sv" for it. Yes, I could have just called the script sv, but I like to follow a naming convention for my scripts: the name before the dot tells me what the script is concerned with; the name after the dot tells me roughly what it does.

dr: produce a pseudo-random sequence

#!/bin/sh #dr: produce a pseudo-random sequence, simulating n rolls of an m-sided die

echo '' |
awk '
BEGIN {
    srand();
}
{
    limit = limit + 0;
    if (limit == 0)
	limit = 2;
    sides = sides + 0;
    if (sides == 0)
	sides = 6;
    for (i=1;i<=limit;i++)
	printf("%s ", 1+int(rand()*sides));
    printf("\n");
}
' limit=$1 sides=$2


[back to Scripts index] [back to Linux, Unix, etc] [Main Site] [Weblog]



Contents licensed under the GPL