Links with good documentation about bash
echo "$SHELL" /bin/bash
Also, you can quote a single character using backslash(\), it's called backslash-escaping.
Hot keys in Bash
Builtin variables
Create alias
- Linux Shell Scripting Tutorial (LSST) v2.0
- Advanced Bash-Scripting Guide
- Shell initialization files
- Great FAQ on BASH
Quoting in bash
There are two types of quoting: strong quotes(' ') and weak quotes(” ”). Strong quotes mean to treat all symbols inside them as literally symbols. Weak quotes treat some special characters as special characters… :) For example dollar sign:
There are two types of quoting: strong quotes(' ') and weak quotes(” ”). Strong quotes mean to treat all symbols inside them as literally symbols. Weak quotes treat some special characters as special characters… :) For example dollar sign:
echo "$SHELL" /bin/bash
Also, you can quote a single character using backslash(\), it's called backslash-escaping.
Hot keys in Bash
- Ctrl-z - suspend key, puts the currently running process in background and pause it
- Ctrl-c - kills the current command or process, by sending to it SIGINT(2) signal
- CTRL-\ - stops command
- Ctrl-d - kills the shell an End of file in commands
- Ctrl-m - similar to press enter
- To see al your control keys: stty -a
- $! - PID of last background job
- $_ - final argument of previous command executed
- $? - exit status of last command
- $$ - Process ID (PID) of the script itself
- $# - amount of arguments
- $0 - the command itself
Read file line by line
while read line
do
echo "$line"
done
do
echo "$line"
done
For example to launch “ls –color” instead of “ls”.In .bashrc file:
alias ls="ls --color"
alias ..='cd ..'
alias d='ls -l | grep -E "^d"'
To redirect standard output and standard error to one file
program > file 2>&1
Logical operations
alias ls="ls --color"
alias ..='cd ..'
alias d='ls -l | grep -E "^d"'
To redirect standard output and standard error to one file
program > file 2>&1
Double bars || mean logical OR.
For example command2 will be launched only if command1 fails:
command1 || command2
Double ampersands && mean logical AND.
For example, command 2 will be launched only if command1 is successful:
command1 && command2
For example command2 will be launched only if command1 fails:
command1 || command2
Double ampersands && mean logical AND.
For example, command 2 will be launched only if command1 is successful:
command1 && command2
No comments:
Post a Comment