4f3327 Add cli_readFileContent.sh.

Authored and Committed by areguera 14 years ago
Scripts/Bash/Functions/cli_readFileContent.sh ADDED
@@ -0,0 +1,61 @@
1
+ #!/bin/bash
2
+ #
3
+ # cli_readFileContent.sh -- This function outputs content files, passed
4
+ # as first argument, to standard output as specified by second
5
+ # argument.
6
+ #
7
+ # Copyright (C) 2009-2011 Alain Reguera Delgado
8
+ #
9
+ # This program is free software; you can redistribute it and/or
10
+ # modify it under the terms of the GNU General Public License as
11
+ # published by the Free Software Foundation; either version 2 of the
12
+ # License, or (at your option) any later version.
13
+ #
14
+ # This program is distributed in the hope that it will be useful, but
15
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ # General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with this program; if not, write to the Free Software
21
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22
+ # USA.
23
+ #
24
+ # ----------------------------------------------------------------------
25
+ # $Id$
26
+ # ----------------------------------------------------------------------
27
+
28
+ function cli_readFileContent {
29
+
30
+ local FILES="$1"
31
+
32
+ # Verify existence of files.
33
+ cli_checkFiles "$FILES"
34
+
35
+ # Print content of files to standard output.
36
+ case "$2" in
37
+
38
+ '--first-line' )
39
+ cat "$FILES" | head -n 1
40
+ ;;
41
+
42
+ '--last-line' )
43
+ cat "$FILES" | tail -n 1
44
+ ;;
45
+
46
+ '--copyright' )
47
+ # This option prints the first line of a file, if it has a
48
+ # copyright format. This option is mainly used to retrive
49
+ # artistic motif author copyright note from artistic
50
+ # motifs `authors.txt' file.
51
+ local PATTERN='^Copyright (\(C\)|©) [0-9]+(-[0-9]+)? .+$'
52
+ if [[ $(cli_readFileContent "$FILES" '--first-line') =~ "${PATTERN}" ]];then
53
+ cli_readFileContent "$FILES" '--first-line'
54
+ fi
55
+ ;;
56
+
57
+ '--all-lines' | * )
58
+ cat "$FILES"
59
+ esac
60
+
61
+ }