Bash Scripts

Here you can find some maybe helpful bash commands under linux.

If you are searching bash commands for ImageMagick's convert or Mplayer / Mencoder you should check my videotools page.

Embedding fonts into PDF - embedfontsintopdf

If you have to embed fonts into a PDF document, you can download my embedfontsintopdf shell script which uses gs and pdffonts to embed all used fonts (also standard fonts). This can be helpful if you have to prepare a final paper submission for IEEE pdfeXpress.

noglob - Secure rm bash command with wildcard extension check (rm * ~ vs. rm *~)

Sometimes this situation happens: you type on the CLI 'rm * ~' instead of 'rm *~'. The former would delate all the files in your cwd, the latter would just do that what you wanted, i.e. cleanup emacs backup files.

That's why I wanted a script which just looks if there is a '*' in the argv of the rm command. Due to the wildcard extension of the bash, this is not so trivial, as the '*' would be extended before passing it to such a script.

But here is the solution using a magic alias. Create a short script (e.g. in python), which parses your argument vector for a lonely '*' pattern. Save this executable script e.g. as ~/bin/ in your private bin-folder.

#! /usr/bin/env python
import sys, os
from string import split, join

if '*' in sys.argv:
    while not ok:
        print "your rm command contains a '*'. Are you sure? y/[n]"
        if (answer == 'y') or (answer == 'Y'):
        elif (answer == 'n') or (answer == 'N') or (answer == ''):
if execute:
    for arg in sys.argv[1:]:
	#todo: insert escape char where it is necessary
	if not '*' in arg:
             cmd += ' "'+arg+'"'   #special char handling
             cmd += ' '+arg        #wildcard extension -- whitespaces and special chars in combination with '*' might be a problem now ... see todo
    #print "executing", cmd
    print "noop"

Now create a magic alias for the normal rm command without any wildcard extensions just for this command/script. Put this into your ~/.bashrc file:

 noglob_helper() {
     case "$shopts" in
         *noglob*) ;;
         *) set +f ;;
     unset shopts
 alias noglob='shopts="$SHELLOPTS"; set -f; noglob_helper'
 alias rm='noglob ~/bin/'           # rm-secure
 alias rmf='/bin/rm'                      # rm-forced

Then do a source ~/.bashrc to reload your file and try again a 'rm * ~'

Philippe Dreuw
Last modified: Thu Mar 6 12:34:24 CET 2008 Disclaimer. Created Wed Dec 22 18:04:32 CET 2004

Valid HTML 4.01! xemacs logo debian logo