Archive for May, 2010

On-the-fly tokenization in bash

Suppose we want to rename a number of files filename_* to othername_*. A way to do it in bash (without using specialized rename tooling) could be the following:

for i in filename_*; do mv $i othername_${i#*_}; done

The # is something called a bash shell glob. Interesting stuff that is worth a closer look at http://www.gnu.org/software/bash/manual/bashref.html.

references: http://ask.metafilter.com/80862/how-split-a-string-in-bash

Friday, May 28th, 2010 Uncategorized No Comments

Bash for-statements with newline delimiters / for-statements over files with spaces

The IFS environment variable is used to set delimiters for parsing lists in bash.

By default, IFS=<space><tab><newline>. This gives a problem if we want to iterate through files with a for statement if files or directories contain spaces. We can circumvent this by setting IFS=<newline>.

So, for example, if we want to iterate through all DOC files in a certain directory and remove their executable permissions, we have the following one-stop solution:

export IFS=$’\n’; for i in `find . -name “*.doc”`; do chmod -x “$i”; done

N.B.: <newline> should be set by IFS=$’\n’. Why this is the only way that works, could not be determined with a few simple web searches, so it remains a mystery.

sources: http://discussions.virtualdr.com/archive/index.php/t-72415.html and http://www.unix.com/shell-programming-scripting/42839-preventing-whitespace-delimiter-loop-bash-sh.html

Friday, May 28th, 2010 Uncategorized No Comments

Adding japanese language support in ubuntu

To add japanese language support in ubuntu linux:

  • Install japanese language support from: System -> Administration -> Language support
  • Set your hot key preferences in: System -> Preferences -> IBus Preferences

To $HOME/.bashrc file add the following lines:

export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus
Thursday, May 13th, 2010 Uncategorized No Comments