The Archives

  • 07.Apr.10
    Setting a Timer scripts | rafacas | (3)
    Sometimes I need a timer to focus on something and to alert me when to stop. Remember, we are real commandliners, so we do not want those fancy applications with a lot of features, we need a script ;-) so here it is: #!/bin/bash usage() { name=`basename $0` echo "Usage: $name hh:mm:ss" echo "Example: $name \"00:15:30\"" } if [ $# != 1 ] then usage exit fi IFS=: set -- $* secs=$(( ${1#0} * 3600 + ${2#0} * 60 + ${3#0} )) while [ $secs -gt 0 ] do sleep 1 & printf "\r%02d:%02d:%02d" ...
  • 06.Mar.09
    Accents everywhere (to be removed, obviously) scripts, shell | pfortuny | (2)
    Accents have again (I still live in Spain and do some work for the Spanish Administration) crept into my terminal. This time it was a group of University professors which had to create a lot of files and directories concerning a historical catalog and even though I remember telling the coordinator not to use accents or spaces or any funny characters, they did it. I should have known better... The problem was then to take away all spaces and non-ASCII characters from directory and file names. After thinking about it a bit, I came up with the solution below. There may be ...
  • 17.Jul.08
    Roll the dice scripts | fernape | (5)
    Not a command, but a fun thing anyway. What if you need a dice (as I needed the other day while trying to play a game with my friends) and you don't have one? Bash can do it: $ while true;do let dice="$RANDOM % 6"; let dice=$dice+1;echo $dice;read;clear;done Though it's a long line, this is just an infinite loop in which we use the $RANDOM bash variable which generates a random number between 0 and 32767. After that, we divide it by 6 and take the remainder (so we have a number between 0 and 5) and add 1 to shift the interval ...