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