shell command

Command to the ~./bash_logout so that the history will get cleared when you logout

1
echo `history -c` >> ~/.bash_logout

Get the name of the history file

1
echo "$HISTFILE"

See the current history

1
2
history
history | grep 'du'

Hide and display the cursor in the shell

1
2
3
4
5
# Hide the cursor
echo -e "\033[?25l"

# Display the cursor
echo -e "\033[?25h"

Three ways of multiple line annotation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
:<<EOF
annotation text...
annotation text...
annotation text...
EOF

:<<'
annotation text...
annotation text...
annotation text...
'

:<<!
annotation text...
annotation text...
annotation text...
!

Make file executable

1
chmod +x <file.name>

Use math equation in shell script (example)

1
2
3
4
#!/bin/bash

val=`expr 2 + 2`
echo "sum of two numbers: $val"

Operators in shell script

Enable interpretation of the backslash escapes

1
echo -e

Read varable and assign to a variable <variable.name>

1
read <variable.name>

vi/vim language and affiliated shortcuts

Shell I/O redirection

Reference