Friday, 23 July 2010

Bash

Links with good documentation about 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:

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
Builtin variables
  • $! - 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


Create alias
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
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

No comments:

Post a Comment

Ping does not work

Today I would like to discuss a banal situation: host A is directly connected to host B, ping from host A to host B does not work. What are...