| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
E_NOSUCHFILE=85 |
| 9 |
|
| 10 |
read -p "File: " file |
| 11 |
if [ ! -e "$file" ] |
| 12 |
then |
| 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 |
| 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 |