Function creates a folder but do not cd into the folder if it exists

45 views Asked by At

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

1

There are 1 answers

0
againzz On

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
}