Shell script creation tool

Source: Internet
Author: User

Every time you create a new script, you must add # In front of the script #! Some fixed text such as/bin/bash. The bash Script Creation script can automatically add information such as Bash and date author. After the creation is complete, the system automatically checks whether the syntax is correct. If there is an error, it will help you open it with vim and locate the line with the syntax problem. If the syntax is incorrect, it will force you Not to exit. Press Ctrl + C to exit. Execute the bash script file if it is created.


Usage: keep up with the file name you want to create after this script. The file name should end with. Sh, otherwise it will not be treated as a script file.

#./Create. Sh new_file.sh

#! /Bin/bash #### determine whether the file exists sh =$ (echo $1 | grep-o '. Sh $') # If! ["$ #"-EQ 1] # Then # echo 'synopsis :. /createfile. sh <FILENAME> '# exit # fiif [-a "$1"] thenecho "File $1 is exists. pless input other FILENAME "Exit 1 Elif [-d" $1 "] thenecho" File $1 is directory. pless input other FILENAME "Exit 2 # create the script file Elif [". sh "=" $ sh "] thencat <EOF> $1 #! /Bin/bash # Description: # version: # Author: wukui # license: gpleofdate = $ (date + % F-% H: % m) echo "# Date: $ date "> $1 elsetouch $1 exitfi # determine whether the file is a bash script file, if yes, open and locate the last line if ['shell' = 'file $1 | cut-d'-F3 '] thenvim + $1 elseexitfi # Add the script file run the permission if ['shell' = 'file $1 | cut-d'-F3 '] thenif! [-X "$1"] thenecho "chmod + x $1" chmod U + x $1 &>/dev/nullfifi # Check the syntax. If there is a problem, use Vim to open and locate the problematic line if ['shell' = 'file $1 | cut-d'-F3 '] thenif! 'Bash-N $ 1' thentouch aaaaaaaaaabash-N $1 &> aaaaaaaaaaline =$ (cut-D:-F2 aaaaaaaaaaaa | cut-d'-F3 | sort-U) while [-n "$ line"] dovim + $ line $1 bash-N $1 &> aaaaaaaaaaline =$ (cut-D: -F2 aaaaaaaaaa | cut-D ''-F3 | sort-u) doneelseecho" very good "exitshortrem-F aaaaaaaaaa


If the attachment is opened in Windows notepad, it may not contain line breaks. This is caused by different line breaks between Linux and windoows.

This article is from my record blog, please be sure to keep this source http://wukui.blog.51cto.com/1080241/1437570

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.