bash – expand shell variables ( bash bug resolved )

As you would have noticed in the recent versions of bash, expansion does not work properly when expanding directory names. So, for something like this

cd $varname

if you press tab, then variable name does not expand properly.

If this is something that is bothering you then you can now add the following in your bashrc and revert to older behaviour:

shopt -s direxpand

Hope this helps you.

colors in bash — script to display all the possible colors.

If you wanted to have colors in the bash output (including the colors in PS1-4), don\’t you keep wondering how the color code would look on the terminal. So, I wrote this small script to show the complete color codes. This is how the output would look:

\"Bash

And here is the script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash -
#===============================================================================
#
#          FILE:  colors.sh
#
#         USAGE:  ./colors.sh
#
#   DESCRIPTION:  Bash colors
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  Amit Agarwal (AKA), amit.agarwal@amit-agarwal.co.in
#       COMPANY:  Individual
#       VERSION:  1.0
#       CREATED:  09/21/2009 06:12:07 PM IST
#      REVISION:  ---
#===============================================================================

for c in `seq 0 255`;
do
t=5;
[[ $c -lt 108 ]]&&t=0;
for i in `seq $t 5`;
do
#Display the codes also for easier lookup in terminal
<!--loginview start-->echo $i;${c}<!--loginview end-->
echo -e "<a class="zem_slink" title="Path (computing)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Path_%28computing%29">\\</a>\e[0;48;$i;${c}m|| $i:$c `seq -s+0 $(($COLUMNS/2))|tr -d \'[0-9]\'`\\e[0m";
done;
done

# setup_colors - Adds colors to array CC for global use
# 30 - Black, 31 - Red, 32 - Green, 33 - Yellow, 34 - Blue,
# 35 - Magenta, 36 - Blue/Green, 37 - White,
# 30/42 - Black on Green \'30\\;42\'
<!--loginview start-->function setup_colors(){
declare -a CC;
for i in `seq 0 7`;
do
ii=$(($i+7));
CC[$i]="\\033[1;3${i}m";
CC[$ii]="\\033[0;3${i}m";
done;
CC[15]="\\033[30;42m";
R=$\'\\033[0;00m\';
X=$\'\\033[1;37m\';
export R X;
}
function display_colors(){
for i in $(seq 0 $((${#CC[@]} - 1))); do echo -e "${CC[$i]}[$i]\\n$R"; done
}
\"Reblog
Enhanced by Zemanta

let a cow tell you your fortune

Here\’s something that I saw on commandlinefu yesterday. That sent me thinking about some command to have the cow file picked randomly 🙂 So, here\’s the original command from the commandlinefu:
let a cow tell you your fortune
1
$ fortune | <a class="zem_slink freebase/en/cowsay" title="Cowsay" rel="homepage" href="http://www.nog.net/%7Etony/warez/cowsay.shtml">cowsay</a> -f tux

Let Tux bring the fortune cookie

\"commandlinefu.com\"

by David Winterbottom (codeinthehole.com)

\"\"

Now, for some fun

#!/bin/bash –
#===============================================================================
#
#          FILE:  fortune_cowsay.sh
#
#         USAGE:  ./fortune_cowsay.sh
#
#   DESCRIPTION:  Cowsay with random cow file.. 🙂
#
#       OPTIONS:  —
#  REQUIREMENTS:  —
#          BUGS:  —
#         NOTES:  —
#        AUTHOR:   (),
#       COMPANY:
#       VERSION:  1.0
#       CREATED:  06/01/2010 03:25:59 PM IST
#      REVISION:  —
#===============================================================================

array=( `ls -1 /usr/share/cowsay/ |tr \’\\n\’ \’ \’` )
count=${#array}
random=$((RANDOM%count))

fortune |cowsay -f ${array[$random]%%.cow}

\"Reblog