函数会创建一个文件夹,但如果存在,请不要将其CD到该文件夹​​中

发布于 2025-02-03 15:32:24 字数 597 浏览 3 评论 0原文

以下是我在.zshrc配置文件中添加的函数,以创建Notes文件夹,如果该文件不存在,并且如果存在该文件夹,则必须将其CD cd到该文件夹​​。

function mnotes(){
   if [ ! -d ~/Desktop/Notes ];then
      mkdir ~/Desktop/Notes
   else
      cd ~/Desktop/Notes
}

我设置了一个别名如下:

alias notes=mnotes

在采购.zshrc文件之后。并键入命令注释,它将创建Notes文件夹,但如果存在文件夹,则不会CD中。

在存在文件夹时运行脚本时的错误映像:

Following is the function I have added in the .zshrc configuration file to create a Notes folder if it does not exist and if the folder exists it has to cd to that folder.

function mnotes(){
   if [ ! -d ~/Desktop/Notes ];then
      mkdir ~/Desktop/Notes
   else
      cd ~/Desktop/Notes
}

I have set an alias as follows:

alias notes=mnotes

After sourcing the .zshrc file. and typing the command notes, it will create the notes folder, but doesn't cd into it if the folder exists.

Error Image while running the script when the folder is present:

Error Image while running the script when the folder is present

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽袖吟 2025-02-10 15:32:24

您忘了添加FI以结束说明:

function mnotes(){
   if [ ! -d ~/Desktop/Notes ];then
      mkdir ~/Desktop/Notes
   else
      cd ~/Desktop/Notes
   fi
}

You forgot to add the fi to end close the statement:

function mnotes(){
   if [ ! -d ~/Desktop/Notes ];then
      mkdir ~/Desktop/Notes
   else
      cd ~/Desktop/Notes
   fi
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文