-1

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

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Santhosh Pai
  • 1
  • 1
  • 1

1 Answers1

0

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
}
againzz
  • 16
  • 1