Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # scrip - generate a script and run it
- #
- # Usage: mksh {-x} [script_name]
- #
- USAGE="Usage: mksh {-x} [script_name]"
- fpath=""
- exec=""
- case $# in
- 0 ) echo -e $USAGE; exit 0 ;;
- 1 ) fpath="$1" ;;
- 2 ) if [ $1 = "-x" ]
- then
- exec="Y"
- fpath="$2"
- else
- echo -e $USAGE
- exit 0
- fi ;;
- esac
- if [ -e $fpath ]
- then
- echo "File exists, please choose another filename."
- exit 0
- else #proceed
- # Get the filename from the full path.
- fname=`echo "${fpath}" |sed 's/.*\///'`
- # Add #!/bin/bash and a header line.
- echo -e "#!/bin/bash\n#\n# ${fname} - ">>$fpath
- # Get the length of the filename, add 6 to get the length of line 3.
- fname_length=6
- let fname_length+="${#fname}"
- # Open in nano with cursor at the end of line 3.
- nano -c +3,$fname_length $fpath
- wait $!
- if [ -e $fpath ]
- then
- chmod +x "${fpath}"
- if [ "$exec" = "Y" ]
- then
- ./$fpath
- fi
- elif [ "$exec" = "Y" ]
- then
- echo "File was not written; execution cancelled."
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement