Bash

man bash - Read it! It’s worth your time.

.bashrc

$HOME/.bashrc is executed when Bash starts. Add stuff you want to keep for every session (like Completion or Silence). Don’t want to restart Bash? Then source it with run source ~/.bashrc.

Sourcing

man says “Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename.”. The following lines are equivalent:

source some_file
. some_file

Completion

These line activate Bash completion:

if [[ -f /etc/bash_completion ]]; then
    . /etc/bash_completion
fi

You may want to install bash-completion and python-optcomplete.

Silence

Disable beep:

setterm -blength 0

You also can make music with beeps. See simpsons.sh.

Bash and Python

... go well together:

python << EOF
print 'hello world'
EOF

See also Python!

Quoting

1
2
3
4
#!/bin/bash
x="hello"
echo "$x world"
echo '$x world'

Simply copy and paste it to your running Bash session and see what happens.

Absolute Path of Script

1
2
3
echo "This file: $0"
echo "Absolute path of this file: $(readlink -m $0)"
echo "Absolute path of this file's parent directory: $(dirname $(readlink -m $0))"

Simply copy and paste it to your running Bash session and see what happens.