Every time when you write shell script, it is sick to type the same head on every script? If you are, try this small script to add head to your code.
#!/bin/sh
help(){
echo "Usage: "
echo " `basename $0`
echo " `basename $0` -h "
exit 1
}
if [ $# -lt 1 ] || [[ $1 = -h ]]
then
help
fi
echo " "
echo "Input the title of your code:"
read line
newline[0]='#!/bin/sh'
newline[1]="#######################################"
newline[2]="# $1"
newline[3]="# $line"
newline[4]="# "
newline[5]="# Created by Your name (you@email.com)"
newline[6]="# on `date`"
newline[7]='# Usage: '
newline[8]='# '
newline[9]='# Modifications: '
newline[10]='# '
newline[11]='#######################################'
newline[12]=' '
newline[13]='help() {'
newline[14]=' echo ""'
newline[15]=' echo "Usage: $0 <>"'
newline[16]=' echo " <>"'
newline[17]=' echo " -h or no-args for this help info."'
newline[18]=' echo ""'
newline[19]='}'
newline[20]='if [[ $1 == "-h" ]] || [ $# -lt 1 ]'
newline[21]=' then'
newline[22]=' help'
newline[23]=' exit 0'
newline[24]='fi'
#this total value must be equal to the last index!!!
total=24
index=0
while [ $index -le $total ]
do
((iline=index+1))
sed -i "${iline}i\\${newline[$index]}" $1
((index+=1))
done
Sunday, April 1, 2007
SHELL: add head to a bash script
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment