1、写脚本时自动生成 #!/bin/bash
1.1、创建脚本vim.sh
#!/bin/bash
p=`pwd`
#判断是否存在该脚本
while((1))
do
{
read -p "Please enter the name of your script: " name
s=$p/$name.sh
if [ ! -e $s ]
then
#如不存在,跳出循环
break
else
echo -e "\033[31m $s already exists \033[0m"
fi
}
done
#建立脚本
touch $s
echo "#!/bin/bash" >> $s
vim $s
1.2、把脚本vim.sh所在路径加入全局环境变量PATH,我这里路径是/pack/
vim /etc/profile
#使配置生效
source /etc/profile
#给与vim.sh执行权限
chmod u+w /pack/vim.sh
完成后,在任意目录下执行vim.sh,输入想创建的脚本名称及可创建带#!/bin/bash的脚本。