shell之創建文件夾:
[root@vbox-nginx shell_command]# vi ./mkdir.sh #!/bin/shparentDir="/media/sf_Project/self/smarty-frame/application/$1"fileName=$2dirAndName=$parentDir/$fileNameif [ ! -d "$dirAndName" ];thenmkdir $dirAndNameecho "創建文件夾成功"elseecho "文件夾已經存在"fi[root@vbox-nginx shell_command]# cat ./mkdir.sh #!/bin/shparentDir="/media/sf_Project/self/smarty-frame/application/$1"fileName=$2dirAndName=$parentDir/$fileNameif [ ! -d "$dirAndName" ];thenmkdir $dirAndNameecho "創建文件夾成功"elseecho "文件夾已經存在"fi
調用shell創建文件夾:
[root@vbox-nginx shell_command]# ./mkdir.sh ApiLoveHouse Model //上級文件夾 要創建的文件夾名創建文件夾成功
shell之創建php文件:
[root@vbox-nginx shell_command]# vi ./mkfile.sh #!/bin/shparentDir="/media/sf_Project/self/smarty-frame/application/$1"fileName=$2dirAndName="$parentDir/$fileName.php"string=${parentDir#*application}namespace=$(echo $string | sed 's#//#//#g')echo $stringecho $namespaceif [ ! -d "$parentDir" ];thenecho "父級文件夾路徑錯誤"elsecd $parentDirif [ ! -f "$dirAndName" ];thentouch $dirAndNameecho "<?php" > $dirAndNameif [[ $fileName == *$strCon* ]];thentouch $dirAndNameecho "<?php" > $dirAndNameif [[ $fileName == *$strCon* ]];thenecho "namespace App$namespace;" >> $dirAndNameelif [[ $fileName == *$strMod* ]];thenecho "namespace App/$namespace;" >> $dirAndNameelse echo "當前只能創建controller和model文件"fiecho "" >> $dirAndNameecho "class $fileName{" >> $dirAndNameecho " //" >> $dirAndNameecho "}" >> $dirAndNameecho "?>" >> $dirAndNameecho "文件創建完成"elseecho "文件已經存在"fi fifi
或
#!/bin/shparentDir=$1fileName=$2dirAndName="$parentDir/$fileName.php"if [ ! -d "$parentDir" ];thenecho "父級文件夾路徑錯誤"elsecd $parentDirif [ ! -f "$dirAndName" ];thencat>$dirAndName<<EOF<?phpnamespace App;class $fileName{ //}?>EOFecho "文件創建完成"elseecho "文件已經存在"fifi
調用shell創建文件:
[root@vbox-nginx shell_command]# ./mkfile.sh ApiLoveHouse/Controllers WelcomeController //上級文件夾 要創建的文件名文件創建完成
shell 在已有文件中追加多行內容
通過 cat>>文件<<EOF EOF 來實現文件追加多行內容
執行
cat >>/test/appendLine.conf<<EOF我是第二行我是第三行EOF
顯示結果為:
到此這篇關于shell之創建文件及內容的方法示例的文章就介紹到這了,更多相關shell 創建文件及內容內容請搜索武林網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持武林網!
新聞熱點
疑難解答