bash regular expressions

2011-02-06 1 min read Bash

Here are some quick links on bash regular expressions, pretty good links to bookmark, if you use, regular expressions in bash regularly. I especially like the tldp link at number 3.

http://www.linuxjournal.com/content/bash-regular-expressions
http://www.ibm.com/developerworks/library/l-bash.html
http://tldp.org/LDP/abs/html/parameter-substitution.html#VARMATCH
http://wellington.pm.org/archive/200005/codegen/index9.htm

Enhanced by Zemanta

shopt causes bash completion to stop working.

2011-01-25 1 min read Bash

Couple of days, I added some scripts to my bash startup and suddenly realized that bash completions stopped working. This is tricky situation in bash to figure out what went wrong. So, I set my foot down to make sure that I find out the culprit. Thus I started with method of elimination. So, I started with nothing in .bashrc and kept adding my stuff in batches, until the said feature was broken. Once that happened I started removing the added ones, one by one, until my completion started working again.

Continue reading

Find all the missing paths in the PATH variable in bash script

2011-01-20 1 min read Bash Fedora Learning

Here is a simple script that will list out all the paths in the PATH variable that do not exist.

  <td>
    <div class="text codecolorer">
      #!/bin/bash -<br /> #===============================================================================<br /> #<br /> #          FILE:  wrong_path.sh<br /> #<br /> #         USAGE:  ./wrong_path.sh<br /> #<br /> #   DESCRIPTION:  Show Directories in the PATH Which does NOT Exist<br /> #<br /> #       OPTIONS:  ---<br /> #  REQUIREMENTS:  ---<br /> #          BUGS:  ---<br /> #         NOTES:  ---<br /> #        AUTHOR:  Amit Agarwal (AKA), amit.agarwal@amit-agarwal.co.in<br /> #       COMPANY:  Individual<br /> #       VERSION:  1.0<br /> #       CREATED:  09/20/2009 09:15:48 AM IST<br /> #      REVISION:  ---<br /> #===============================================================================<br /> <br /> set -o nounset                              # Treat unset variables as an error<br /> <br /> (IFS=:;for p in $PATH; do test -d $p || echo $p; done)
    </div>
  </td>
</tr>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

bash 4.0 – new feature mapfile

2011-01-14 1 min read Bash Fedora

Recently I encountered a problem where I had to create couple of arrays in bash and these were quite dynamic in nature. This script was supposed to be used by couple of guys whom I did not trust too much in opening the script and modifyikng the array. So, the solution was to put these in different files and then put them in array using bash script itself. This is when I went through the bash man page again and found an interesting new inbuilt mapfile

Continue reading

perl is faster than bash in some cases.

2011-01-11 3 min read Bash Fedora Linux Perl

Some days back, I had to generate some data to be uploaded to a database. As usual I assumed that bash should be faster and hence wrote the script to create the files in bash. But I found that even after 5 hours I was only 10% done with the data generation. Now that would mean that it would take around 50 hours to complete the data generation. Something did not look correct to me and I asked one of my colleague. He suggested I do a strace.

Continue reading
Older posts Newer posts