ambevar-dotfiles/.scripts/prepend

20 lines
300 B
Bash
Executable File

#!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat <<EOF
Usage: ${0##*/} STRING [FILES]
Prepend STRING to FILES or stdin if unspecified. STRING may not contain pipes
('|').
EOF
exit
fi
VAR="$1"
shift
[ $# -eq 0 ] && OPT_INPLACE="" || OPT_INPLACE="-i"
sed $OPT_INPLACE "1i$VAR" "$@"