There are several ways to tell Bash to treat numbers as integers instead of strings, and to do basic arithmetic operations on them. The first is to use the
let command:
In addition to the let command, one may use the (( )) syntax to enforce an arithmetic context. If there is a $ (dollar sign) before the parentheses, then a substitution is performed (more on this below). White space is allowed inside (( )) with much greater leniency than with normal assignments, and variables inside (( )) don't require $ (because string literals aren't allowed).
let WC=$(sudo wc -l $MAIN_FILE | cut -d" " -f1 )
((WC=$WC - 1 ))
echo $WC
comment #
$ ls # kjenvdlkvndlkvnldk ndlkvn dlk vndlkvdlkdlldk anything after # is comment
#!/bin/bash
echo Hello World
Bash Keyboard shortcuts
Ctrl + A: Go to the beginning of the line you are currently typing on
Ctrl + E: Go to the end of the line you are currently typing on
•
Ctrl + F: Forward one character.
•
Ctrl + B: Backward one character.
•
Meta + F: Move cursor forward one word on the current line
•
Meta + B: Move cursor backward one word on the current line
•
Ctrl + P: Previous command entered in history
•
Ctrl + N: Next command entered in history
•
Ctrl + L: Clears the screen, similar to the clear command
•
Ctrl + U: Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
•
Ctrl + H: Same as backspace
•
Ctrl + R: Lets you search through previously used commands
•
Ctrl + C: Kill whatever you are running
•
Ctrl + D: Exit the current shell
•
Ctrl + Z: Puts whatever you are running into a suspended background process. fg restores it.
•
Ctrl + W: Delete the word before the cursor
•
Ctrl + K: Kill the line after the cursor
•
Ctrl + Y: Yank from the kill ring
$ echo `hostname` | sed 's/ip/foo/g'