Debian Codegraph @

prepend.sh

raw symbols SCIP
1 #!/bin/bash
2 # prepend.sh: Add text at beginning of file.
3 #
4 # Example contributed by Kenny Stauffer,
5 #+ and slightly modified by document author.
6
7
8 E_NOSUCHFILE=85
9
10 read -p "File: " file # -p arg to 'read' displays prompt.
11 if [ ! -e "$file" ]
12 then # Bail out if no such file.
13 echo "File $file not found."
14 exit $E_NOSUCHFILE
15 fi
16
17 read -p "Title: " title
18 cat - $file <<<$title > $file.new
19
20 echo "Modified file is $file.new"
21
22 exit # Ends script execution.
23
24 from 'man bash':
25 Here Strings
26 A variant of here documents, the format is:
27
28 <<<word
29
30 The word is expanded and supplied to the command on its standard input.
31
32
33 Of course, the following also works:
34 sed -e '1i\
35 Title: ' $file