« May 2013»
M T W T F S S
    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    

[blog...]

22.07.2011
16:07

Bash Commandline Completion - Bugfix for Ubuntu 11.04

Bash completion is action

Since my update to Ubuntu 11.04 I missed a very, very useful and important feature for people like me, working most of the time on the console.

 

I don't care which window-manager-system-style I'm using. GNOME, KDE, LXDE or whatever as long as the terminal is starting fast.

 

In Ubuntu 11.04 is a bug with the bash_completion. This helps you completing the filenames with the TAB-key. Especially with filenames and directories with spaces or German "Umlaute".

Right now, I spent half an hour to google for a solution and it's so simple. There is only an error in /etc/bash_completion (line 1587):

 

# makeinfo and texi2dvi are defined elsewhere. 
for i in a2ps awk bash bc bison cat colordiff cp csplit \
curl cut date df diff dir du enscript env expand fmt fold gperf gprof \
grep grub head indent irb ld ldd less ln ls m4 md5sum mkdir mkfifo mknod \
mv netstat nl nm objcopy objdump od paste patch pr ptx readelf rm rmdir \
sed seq sha{,1,224,256,384,512}sum shar sort split strip tac tail tee \
texindex touch tr uname unexpand uniq units vdir wc wget who; do
have $i && complete -F _longopt -o filenames $i
done

 

This bug has been discussed on the bugtracker at launchpad:

https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/769866

back

29.10.2009
19:43

Replace Bash Indirect Variable Expansion Feature

replace bash syntax {!VAR} with POSIX conform equivalent

Debian and Ubuntu changed the default shell /bin/sh from bash (Bourne Again Shell) to dash (Debian Almquist Shell).

The advantage of dash is its size, speed and POSIX compliance. The disadvantage is that many scripts written for bash won't work anymore because bash has specific features - so called "bashisms".

 

One of this bashisms, I used frequently in the xxsvideo build system is the " indirect variable expansion". Which makes it possible to execute the following script:

 

#!/bin/bash                                                                                                                                        
                                                                                                                                                  
CONFIG_BUSYBOX=y

PACKAGENAME="BUSYBOX"
PACKAGECONFIG=CONFIG\_$PACKAGENAME

if [ "${!PACKAGECONFIG}" = "y" ]; then
        echo $PACKAGENAME "is selected"
else
        echo $PACKAGENAME "is NOT selected"
fi

 

If you call this script with bash you receive as expected "BUSYBOX is selected".

With dash you see:

 

./test.sh: 13: Bad substitution

 

I was looking a long time for the right way to replace this {!VAR} statement. But it's quite simple and suddenly I found a thread describing it:

 

#!/bin/dash

 

 


CONFIG_BUSYBOX=y

 

 


PACKAGENAME="BUSYBOX"

 

 


PACKAGECONFIG=CONFIG\_$PACKAGENAME

 

 


if [ "$(eval echo '$'$PACKAGECONFIG)" = "y" ]; then

 

 

    echo $PACKAGENAME "is selected"

 

 

else

 

 

    echo $PACKAGENAME "is NOT selected"

 

 

fi

 

 

In short: With dash you write:

 

eval echo '$'$VARIABLE

 

which is equivalent to bash

 

echo ${!VARIABLE}

 

 

... I think ;-)

 

back

[ 26.02.2013 ]