You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

zshrc file, .zsenv file. Config file

I am learning how to write and run scripts from Terminal window.

I understand that it is related to content of files where i specify location of my scripts

directory, my own functions and granting proper permissions to my scripts.

These files are:

.zshrc

.zsenv, and

config file

I need answers to the following questions:


1. how do i tell the operating system where the config file is located?

2. how do I tell the system where my own functions are located?


At this time my .zshrc file looks like follwing:


export PATH=$PATH:/Users/grigoryzubkis

chmod 755 /Users/grigoryzubkis/RunIt

chmod 755 /Users/grigoryzubkis/simplemenu.sh

chmod 755 /Users/grigoryzubkis/learnUnix.sh

chmod 755 /Users/grigoryzubkis/l.sh

Posted on Jun 9, 2022 9:44 AM

Reply
Question marked as Top-ranking reply

Posted on Jun 9, 2022 1:54 PM

I am sorry. Please, disregard my last question ---> "Can I just supply a directory name , where I keep all my new functions?"

the solution was really simple. --->


to supply in my .zshrc file the directory for new functions --> "export PATH=$PATH:/Users/grigoryzubkis/MyFunctions" 

and supply "CHMOD" statement for new script ----> "chmod   755 /Users/grigoryzubkis/bin/script#2"

to put the new function into function directory "/Users/grigoryzubkis/MyFunctions"


Best Regards


Similar questions

5 replies
Question marked as Top-ranking reply

Jun 9, 2022 1:54 PM in response to grigory193

I am sorry. Please, disregard my last question ---> "Can I just supply a directory name , where I keep all my new functions?"

the solution was really simple. --->


to supply in my .zshrc file the directory for new functions --> "export PATH=$PATH:/Users/grigoryzubkis/MyFunctions" 

and supply "CHMOD" statement for new script ----> "chmod   755 /Users/grigoryzubkis/bin/script#2"

to put the new function into function directory "/Users/grigoryzubkis/MyFunctions"


Best Regards


Jun 9, 2022 10:29 AM in response to grigory193

I do not think zsh has a 'config' file that it uses. Some other utilities might, but shells tend to use .mumble files.


man zsh

gives you a list of the different zsh initialization files

       $ZDOTDIR/.zshenv
       $ZDOTDIR/.zprofile
       $ZDOTDIR/.zshrc
       $ZDOTDIR/.zlogin
       $ZDOTDIR/.zlogout
       ${TMPPREFIX}*   (default is /tmp/zsh*)
       /etc/zshenv
       /etc/zprofile
       /etc/zshrc
       /etc/zlogin
       /etc/zlogout    (installation-specific - /etc is the default)


By default $ZDOTDIR is your home folder, also referenced as $HOME


STARTUP/SHUTDOWN FILES
       Commands  are  first read from /etc/zshenv; this cannot be overridden.  Subsequent behaviour
       is modified by the RCS and GLOBAL_RCS options; the former affects all startup  files,  while
       the  second only affects global startup files (those shown here with an path starting with a
       /).  If one of the options is unset at any point, any subsequent startup file(s) of the cor‐
       responding  type  will not be read.  It is also possible for a file in $ZDOTDIR to re-enable
       GLOBAL_RCS. Both RCS and GLOBAL_RCS are set by default.

>>   Commands are then read from $ZDOTDIR/.zshenv.  If the shell is a login shell,  commands  are
>>   read  from  /etc/zprofile  and  then $ZDOTDIR/.zprofile.  Then, if the shell is interactive,
>>   commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc.  Finally,  if  the  shell  is  a
>>   login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.

       When  a login shell exits, the files $ZDOTDIR/.zlogout and then /etc/zlogout are read.  This
       happens with either an explicit exit via the exit or logout commands, or an implicit exit by
       reading  end-of-file  from  the  terminal.  However, if the shell terminates due to exec'ing
       another process, the logout files are not read.  These are also  affected  by  the  RCS  and
       GLOBAL_RCS options.  Note also that the RCS option affects the saving of history files, i.e.
       if RCS is unset when the shell exits, no history file will be saved.

       If ZDOTDIR is unset, HOME is used instead.  Files listed above as being in /etc  may  be  in
       another directory, depending on the installation.

       As  /etc/zshenv is run for all instances of zsh, it is important that it be kept as small as
       possible.  In particular, it is a good idea to put code that does not need  to  be  run  for
       every single shell behind a test of the form `if [[ -o rcs ]]; then ...' so that it will not
       be executed when zsh is invoked with the `-f' option.

       Any of these files  may  be  pre-compiled  with  the  zcompile  builtin  command  (see  zsh‐
       builtins(1)).   If  a compiled file exists (named for the original file plus the .zwc exten‐
       sion) and it is newer than the original file, the compiled file will be used instead.


Unix traditions would have you create a folder

/Users/grigoryzubkis/bin


Add that to your PATH

export PATH="$PATH:/Users/grigoryzubkis/bin"

and put all your scripts into your personal bin directory.


This is just tradition, it is not a rule, it is not absolute, and you can do anything you please.


Just putting an export command into your .zshrc file does not cause it to be invoked. You have to generally either exit from your Terminal session and start a new one, or issue the command

source $HOME/.zshrc

to get zsh to re-read your .zshrc file.

Or you can manually execute the export command from a zsh shell prompt.


The .zshrc file is so that when you start a New Terminal session, zsh gets all your settings in your various shell initialization files.


It is also not a good idea to be changing the /etc/ versions of the shell initialization files. For example, is you use Migration Assistant to move from an older Mac to a newer Mac, your home folder can be transferred, but the /etc/ directory is not, so you would loose them.


The /etc/ versions of shell initialization files are more for a corporate environment where the company need for you to have some common settings (most common environment variables) so that you can properly work in the corporate environment. As a personal user, you do not have that situation.

Jun 9, 2022 1:10 PM in response to BobHarris

Thanks a lot!

I have followed Your suggestions, and it had worked great!!!!!.

this is how my .zshrc file looks now:


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


export PATH=$PATH:/Users/grigoryzubkis/bin

chmod   755 /Users/grigoryzubkis/bin/RunIt

chmod   755 /Users/grigoryzubkis/bin/simplemenu.sh

chmod   755 /Users/grigoryzubkis/bin/learnUnix.sh

chmod   755 /Users/grigoryzubkis/bin/script#1

chmod   755 /Users/grigoryzubkis/bin/function#1


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


I have one more question. You have noticed, that I have a statement "chmod   755 /Users/grigoryzubkis/bin/function#1" in my .zshrc file. Right?

So basically every time i create a new function, I have to put "chmod" statement referring to this new function into .my .zshrc file?

Can I just supply a directory name , where I keep all my new functions?

Thanks a lot.






zshrc file, .zsenv file. Config file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.