Difference between revisions of "Bash"

From Linuxintro
imported>ThorstenStaerk
imported>ThorstenStaerk
Line 33: Line 33:
 
= bash completion =
 
= bash completion =
 
Bash completion is configured in all files under /etc/bash_completion.d/. [http://wiki.bennyshome.de/Bash_completion_f%C3%BCr_Dell_OMSA Here] is an example.
 
Bash completion is configured in all files under /etc/bash_completion.d/. [http://wiki.bennyshome.de/Bash_completion_f%C3%BCr_Dell_OMSA Here] is an example.
 +
 +
= Konsole prompt =
 +
Enter into .bashrc:
 +
export PS1='\[\033]0;\007\]\[\033]30;\u@\h\007\]\u@\h:\w\$ '

Revision as of 05:30, 3 September 2010

Bash is the default shell in most Linuxes, for example in SUSE Linux. If you call it, you get a prompt like this:

tweedleburg:~ #

for a computer named tweedleburg. To start a program, just type its name and Enter, e.g.

tweedleburg:~ # firefox

To find out what shell you are in, echo the SHELL variable, like this:

tweedleburg:~ # echo $SHELL
/bin/bash

Programming

You can use your shell to execute little programs written in bash. For example, if you have a file myprogram containing the text

#!/bin/bash
echo "What is your name "
read name 
echo "Hello $name"

You can execute it and will be greeted by the name you give.

tweedleburg:~ # bash myprogram
What is your name
Thorsten
Hello Thorsten
tweedleburg:~ #

for loop

for ((i=1; i<6; i++)); do
  echo $i
done

OR

for i in `seq 1 5`; do echo $i; done

foreach file

This does a hexdump operation on all files:

for file in * ; do hexdump $file ${file%.*} ; done

bash completion

Bash completion is configured in all files under /etc/bash_completion.d/. Here is an example.

Konsole prompt

Enter into .bashrc:

export PS1='\[\033]0;\007\]\[\033]30;\u@\h\007\]\u@\h:\w\$ '