shell之創建文件及內容


shell之創建文件夾:

[root@vbox-nginx shell_command]# vi ./mkdir.sh 
#!/bin/sh

parentDir="/media/sf_Project/self/smarty-frame/application/$1"
fileName=$2
dirAndName=$parentDir/$fileName
if [ ! -d "$dirAndName" ];then
mkdir $dirAndName
echo "創建文件夾成功"
else
echo "文件夾已經存在"
fi
[root@vbox-nginx shell_command]# cat ./mkdir.sh 
#!/bin/sh

parentDir="/media/sf_Project/self/smarty-frame/application/$1"
fileName=$2
dirAndName=$parentDir/$fileName
if [ ! -d "$dirAndName" ];then
mkdir $dirAndName
echo "創建文件夾成功"
else
echo "文件夾已經存在"
fi

調用shell創建文件夾:

[root@vbox-nginx shell_command]# ./mkdir.sh ApiLoveHouse Model        //上級文件夾 要創建的文件夾名
創建文件夾成功

shell之創建php文件:

[root@vbox-nginx shell_command]# vi ./mkfile.sh 

#!/bin/sh

parentDir="/media/sf_Project/self/smarty-frame/application/$1"
fileName=$2
dirAndName="$parentDir/$fileName.php"
string=${parentDir#*application}
namespace=$(echo $string | sed 's#\/#\\#g')
echo $string
echo $namespace
if [ ! -d "$parentDir" ];then
echo "父級文件夾路徑錯誤"
else
cd $parentDir

if [ ! -f "$dirAndName" ];then

touch $dirAndName
echo "<?php" > $dirAndName

if [[ $fileName == *$strCon* ]];then
touch $dirAndName
echo "<?php" > $dirAndName

if [[ $fileName == *$strCon* ]];then
echo "namespace App$namespace;" >> $dirAndName
elif [[ $fileName == *$strMod* ]];then
echo "namespace App\$namespace;" >> $dirAndName
else 
echo "當前只能創建controller和model文件"
fi

echo "" >> $dirAndName
echo "class $fileName{" >> $dirAndName
echo "          //" >> $dirAndName
echo "}" >> $dirAndName
echo "?>" >> $dirAndName
echo "文件創建完成"
else
echo "文件已經存在"
fi 
fi
fi

#!/bin/sh

parentDir=$1
fileName=$2
dirAndName="$parentDir/$fileName.php"
if [ ! -d "$parentDir" ];then
echo "父級文件夾路徑錯誤"
else
cd $parentDir

if [ ! -f "$dirAndName" ];then
cat>$dirAndName<<EOF
<?php
namespace App;

class $fileName{
        //
}
?>
EOF
echo "文件創建完成"
else
echo "文件已經存在"
fi

fi

調用shell創建文件:

[root@vbox-nginx shell_command]# ./mkfile.sh ApiLoveHouse/Controllers WelcomeController        //上級文件夾 要創建的文件名
文件創建完成

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM