Bash script to add some line to a file at specific line number

I wrote this example to show how to append JAVA_OPTS parameters to of tomcat


s=" export JAVA_OPTS=\"$JAVA_OPTS -Xms1024m -Xmx1024m -XX:MaxPermSize=256m\""
sp=" "
awk -vn="$NLINE" -vs="$s" -vsp="$sp" 'NR==n{$0=$0 sp s}1' >temp
mv temp

Sp is space given so that if something exists in that line it will give some space and
append our command or string