您现在的位置是:网站首页> 编程资料编程资料
shell之创建文件及内容的方法示例_linux shell_
2023-05-26
382人已围观
简介 shell之创建文件及内容的方法示例_linux 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 " $dirAndName if [[ $fileName == *$strCon* ]];then touch $dirAndName echo " $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 echo "文件创建完成" else echo "文件已经存在" fi fi
调用shell创建文件:
[root@vbox-nginx shell_command]# ./mkfile.sh ApiLoveHouse/Controllers WelcomeController //上级文件夹 要创建的文件名 文件创建完成
shell 在已有文件中追加多行内容
通过 cat>>文件<
执行
cat >>/test/appendLine.conf<
显示结果为:
到此这篇关于shell之创建文件及内容的方法示例的文章就介绍到这了,更多相关shell 创建文件及内容内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
您可能感兴趣的文章:
相关内容
- Linux Shell Map的用法详解_linux shell_
- mac使用Shell(终端)SSH连接远程服务器的方法_linux shell_
- shell脚本语言的使用(超全超详细)_linux shell_
- Shell脚本实现猜数字游戏_linux shell_
- shell脚本实现猜数游戏_linux shell_
- Shell实现猜数字游戏_linux shell_
- shell实现猜数字小游戏_linux shell_
- 详解bash中的退出状态机制_linux shell_
- 详解shell脚本中的case条件语句介绍和使用案例_linux shell_
- 如何利用shell开发keepalived启动脚本_linux shell_