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#!/bin/bash
2x="hello"
3echo "$x world"
4echo '$x world'
Simply copy and paste it to your running Bash session and see what happens.
Absolute Path of Script#
1echo "This file: $0"
2echo "Absolute path of this file: $(readlink -m $0)"
3echo "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.
Check if Shell is Interactive#
[[ $- == *i* ]]
From man bash
:
The current set of options may be found in $-.
Links#
- Advanced Bash Scripting Guide: