如果Mac OS的ShellScript中其他语句,您如何编写?
我的目标很简单。我正在尝试编写一个包含 if else 语句的 MacOs Shell 脚本。具体来说,如果我的桌面上存在名为“newFolder”的文件,我希望脚本创建一个名为“targets”的新文件。其次,如果桌面上存在名为“ifolder”的文件夹,我希望脚本创建一个名为“days”的新文件夹,如果不存在,则创建一个名为“reactProjects”的文件夹。
这是我尝试过的:
#!/bin/bash
cd ..
cd ..
cd desktop
if exist newFolder mkdir targets
if exist targets mkdir days else mkdir reactProjects
但是当我尝试通过终端运行它时出现错误。错误指出:
ifExample.sh: line 10: syntax error: unexpected end of file
这是我的第一个脚本 shell,因此我可能有一些语法错误,但如果您了解如何执行此操作,请告诉我。
谢谢!
My goal is a simple one. I am trying to write a MacOs Shell Script containing if else statements. Specifically, I want the script to create a new file called "targets" if a file named "newFolder" exists on my desktop. Secondly I want the script to create a new folder called "days" if a folder named "ifolder" exists on the desktop and if it does not exist create a folder called "reactProjects".
Here is what I've tried:
#!/bin/bash
cd ..
cd ..
cd desktop
if exist newFolder mkdir targets
if exist targets mkdir days else mkdir reactProjects
But I am having an error occur when I try run it through the terminal. The error states:
ifExample.sh: line 10: syntax error: unexpected end of file
This is my first script shell, so I may have some syntax mistakes, but please let me know if you understand how to do this.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该了解有关 bash 中的条件的更多信息,因此我鼓励您阅读这篇文章。
但在此之前您的解决方案应该如下所示:
You should know more about conditionals in bash so I encourage you to read this article.
But before that your solution should look like this: