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 ...
  • 23.Jan.09
    Space for shell | pfortuny | (5)
    So your friend sent you a batch of tiffs to be converted into jpg's (using ImageMagick's convert command). However your friend (who is not so geeky as you) uses spaces in filenames (which is a deadly sin), like in First photo of birthday.tiff Second photo.tiff You wanted to use a shell for loop, but the obvious $ for i in `find . -name *tiff` ; do convert "$i" "${i%tiff}jpg" ; done produces garbage (try it). This is just one of the consequences of your friend's carelessness. But there is a solution. IFS (Internal Field Separator) is a shell variable controlling what character(s) delimit a 'field' in ...