Bash Scripting templates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# ==========================
# Bash tips
# ==========================

# Run bash by
$ /bin/bash scriptname.sh
$ /bin/bash scriptname.sh +x  # debug mode

# Or put the next line on the 1st line of your file.
#!/bin/bash -x

## Double round braket for integer
if (( $MYINT < 10 ]]   #or: =
## Double square braket for string
if [[ $USER = "ron" ]]   #or: !=
   then
      echo "Hello ron"
   else
      echo "Hello Stranger"
fi

$ date +%x   # shows only the date 07/02/13 depending on locale, currently en_CA
$ LANG=en_US
$ date +%x   # shows only the date 02/07/13


# ==========================
# vi tips
# ==========================

# Using normal mode
# Delete line at the cursor
#    type dd
# Insert at cursor
#    type i
# Insert after the cursor (append)
#    type a
k
J
o

# To bring in (read in) the content of an extrnal file into your current file
:r ~/snippets/if

# To read in a result of an executable, such as date use the :r!
:r!date
:r!date "+\%x"

# Macro normal mode
:map
# Macro insert mode
:map!

# Macro F2 to insert text: "#This file was created on 2014-05-03"
:map <F2> i#This file was created on <ESC>:r!date "+\%x" <ESC> kJ

put the line above to .vimrc
map <F2> i#!/bin/bash<ESC>
map <F3> o#This file was created on <ESC>:r!date "+\%x" <ESC> kJ
This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


9 + eight =