New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
template.sh in branches/UKMO/icebergs_restart_single_file/NEMOGCM/TOOLS/COMPILE – NEMO

source: branches/UKMO/icebergs_restart_single_file/NEMOGCM/TOOLS/COMPILE/template.sh @ 5852

Last change on this file since 5852 was 5852, checked in by davestorkey, 8 years ago

UKMO/icebergs_restart_single_file branch : remove SVN keywords

  • Property eol-style set to native
  • Property svn:executable set to *
File size: 7.8 KB
Line 
1#!/bin/bash
2
3
4#§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
5#
6# This template for Bash coding pair with Emacs Lisp package 'bash-font-lock.el'
7# to enhance default shell syntax fontification. This package is based on regexs
8# to match examples of concsyntax showed below.
9# All this is not mandatory and probably not optimized with other correct rules
10# Feel free to add your tips, modify it at your convenience or give your feedback
11# to improve it.
12#
13#§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
14
15
16# To automatically use it with a bash script, copy it to your ~/.emacs.d and
17# add '(load "~/.emacs.d/bash-font-lock.el")' in your .emacs configuration file
18#--------------------------------------------------------------------------------
19 # If a command  is not highlighted, add its name to 'bash-builtins'  list
20 # "  " function ""  "       "     ,  "   "   ""  "" 'bash-functions'  ""
21
22# UNIX built-in commands sample
23#-------------------------------
24.; alias; bg; bind; builtin; caller; compgen; complete; declare; dirs; disown
25enable; fc; fg; help; history; jobs; kill; let; local; popd; printf; pushd
26shopt; source; suspend; typeset; unalias; eval; export; getopts; newgrp; pwd
27read; readonly; times; ulimit; command; hash; test; type; cd; echo; eval; set
28shift; umask; unset; wait
29
30# Common bash built-in commands already added to 'bash-builtins' list
31#---------------------------------------------------------------------
32awk basename cat cp cut date diff dirname env find grep head ls make mkdir mv rm
33sed sort svn tail tee touch uniq xargs
34
35# Variables
36#-----------
37 # Specials    parameters (see Bash manual for details, `man bash`)
38$0 $# $* $@ $? $! $_ $$ $-
39 # Positionnal parameters (ordered arguments given to run script "$0")
40$1 $2 $3 ...               
41$* ==  "$1${IFS}$2${IFS}$3..." #   Single word , recommended use for string
42$@ ==  "$1"    "$2"    "$3"...  # Separate words, recommended use for array
43 # Identify locals against GLOBALS or ENVIRONMENT variables with case sensitive
44TEMP=${temp_0123}; temp=${TEMP_0123}; export TEMP=${TEMP_0123}
45 # Possibles variable assignation syntax
46temp='temp'; temp=$1 # Simple
47length_temp=${#temp} # Length of string
48temp=$(( 1 + 1 ))    # Integer arithmetic evaluation
49temp=${........}     # String operations
50temp=$(test ....)    # Regular syntax
51temp=$( test ... )   # Highlight sub-shell '( ... )' & command or function call
52temp=`test .....`    # Backquotes not recommended to avoid complete highlighting
53
54# Arrays
55#--------
56 # Initialisation
57declare -a array                 # Explicit
58array=([0]='zero' [1]='one' ...) # Implicit with index assignement
59array[0]='zero'; array[9]='ten'  # Implicit or add element to array at an index
60 # Curly brackets are essential to work with arrays
61 # Last index of an array
62IDX=${#temp_0123[@]}; idx=${#TEMP_0123[@]}
63 # Get last element of an array (${#array[@]})
64LAST_ELMNT=array[${#array[@]}]; last_elmnt=ARRAY[${#ARRAY[@]}]
65 # Remove an element or entire array
66unset array[9]; unset array[@]
67
68# Strings
69#---------
70 # Single quotes are recommended to identified entire characters string instead
71 # of doubles quotes or initialize variable
72echo 'The name of the script is '$0' with following arguments '$*
73 # Doubles quotes should only be used when it's necessary to interpret escaping
74 # character or to perform parameter substitution
75printf "The value of PI is %8.6f.\n" $PI; sed "s/3.1415/$PI/" temp.txt
76
77# Function
78#----------
79 # 'function' word is not not mandatory at declaration if you have double
80 # brackets '()' right after name. A function has to be declared before its call
81 # so should be placed at the beginning of the main script. A clever solution is
82 # to gather similar functions in kind of a 'module' file which will be sourced
83 # from main script.
84 # 2 possibles syntax:
85function fake_func { local temp=''; ...; return ...; }
86fake_func() {
87    local temp='' # Declare variable as local, if not his attribute is global
88    ...
89    return ...   # Function can only return an integer (stderr by default)
90                  # export result by a global variable to bypass it
91}
92 # Function call (with or without argument)
93temp=$( fake_func $1 $2 ); fake_func $1 $2; fake_func
94
95# Tests operators differs with type of test (arithmetic or string comparison
96# for number/characters, file attributs), see manual for test with `man test`
97#----------------------------------------------------------------------------
98 # Possible syntax : literal 'test' or compact syntax with brackets/parenthesis
99 # at the ends
100 # '[ ... ]' & '[[ ... ]]' are almost identical (simple and extended test)
101 # With ' != ' & ' == ' operators, right string is considered as          regex
102 #  ""             '~='     "    ,   "     ""   "      ""     "  extended   "
103[ $temp ~= "..." ] && [[ ! -e temp.txt ]] || (( $temp >= 0 ))
104
105# For compound commands, prefer the use of command block '{ ...; }' instead of
106# a sub-shell '( ... )', keep in mind that despite sub-shell inherit from its
107# run script all variables declared as locals are lost at the end of execution
108
109# To cut a long sequence, put the escape character '\' at the end of line and
110# continue on next line (possible on several lines)
111printf "This is a very very very long sentence that I have to cut in order to  \
112        be less than 80 characters for a line of code but I don't have to call \
113        the same command several times.\n                                       "
114# A pipe ' | ' cannot be put at the end of a line, even if you have a '\'
115cat temp.txt | cut -d' ' -f-5 | sort -kr3n | uniq -c | sort | head -n25 \
116| awk '$3 >= 1024 {print $4}'                                           \
117| xargs -t -i() mv () $HOST@$HOSTNAME:${REP_STORAGE}
118
119# 'if ...; then ...; fi'
120#------------------------
121 # Very short syntax with commands block '{ ...; }'
122[ ... ] && { ...; ...; }
123 #      Short syntax with commands block '{ ...; }'
124[ ... ] && { ...; \
125             ...;  }
126 #    Regular syntax
127if [ ... ]; then
128    ... 
129fi
130
131# 'if ...; then ...;  else ...; fi'
132#----------------------------------
133 #   Short syntax with commands block '{ ... }'
134{ [ ... ] && ...; } || { ...; ...; }
135 # Regular syntax
136if [ ... ]; then
137    ...
138else
139    ...
140fi
141
142# 'case ... in ...) ... ;; ... esac'
143#-----------------------------------
144case ... in
145 # Very short syntax
146    ...) ...;;     ...) ...;;    ...) ...;;
147 #      Short syntax
148    ...) ...; ...; ...;;
149 #    Regular syntax
150    ...)
151   ...
152   ;;
153esac
154
155# List font lock faces with effective highlighting (can be customized)
156#---------------------------------------------------------------------
157 font-lock-warning-face
158 # for a construct that is peculiar, or that greatly changes the meaning of
159  #other text
160 font-lock-function-name-face
161 # for the name of a function being defined or declared
162 font-lock-variable-name-face
163 # for the name of a variable being defined or declared
164 font-lock-keyword-face
165 # for a keyword with special syntactic significance, like ‘for’ and ‘if’ in C.
166 font-lock-comment-face
167 # for comments
168 font-lock-comment-delimiter-face
169 # for comments delimiters, like ‘/*’ and ‘*/’ in C. On most terminals, this
170  #inherits from font-lock-comment-face
171 font-lock-type-face
172 # for the names of user-defined data types
173 font-lock-constant-face
174 # for the names of constants, like ‘NULL’ in C
175 font-lock-builtin-face
176 # for the names of built-in functions
177 font-lock-preprocessor-face
178 # for preprocessor commands. This inherits, by default, from
179  #font-lock-builtin-face
180 font-lock-string-face
181 # for string constants
182 font-lock-doc-face
183 # for documentation strings in the code. This inherits, by default, from
184  #font-lock-string-face
185 font-lock-negation-char-face
186 # for easily-overlooked negation characters
Note: See TracBrowser for help on using the repository browser.