| 1 | #!/bin/bash |
| 2 | |
| 3 | # Noninteractive use of 'vi' to edit a file. |
| 4 | # Emulates 'sed'. |
| 5 | |
| 6 | E_BADARGS=85 |
| 7 | |
| 8 | if [ -z "$1" ] |
| 9 | then |
| 10 | echo "Usage: `basename $0` filename" |
| 11 | exit $E_BADARGS |
| 12 | fi |
| 13 | |
| 14 | TARGETFILE=$1 |
| 15 | |
| 16 | # Insert 2 lines in file, then save. |
| 17 | #--------Begin here document-----------# |
| 18 | vi $TARGETFILE <<x23LimitStringx23 |
| 19 | i |
| 20 | This is line 1 of the example file. |
| 21 | This is line 2 of the example file. |
| 22 | ^[ |
| 23 | ZZ |
| 24 | x23LimitStringx23 |
| 25 | #----------End here document-----------# |
| 26 | |
| 27 | # Note that ^[ above is a literal escape |
| 28 | #+ typed by Control-V <Esc>. |
| 29 | |
| 30 | # Bram Moolenaar points out that this may not work with 'vim' |
| 31 | #+ because of possible problems with terminal interaction. |
| 32 | |
| 33 | exit |