About /home/<user_name>/.bashrc and /etc/bashrc
From Centos 7, home/<user_name>/.bashrc :
Code:
# .bashrc semantically it is like this: If file /etc/bashrc exists, then run this command: Code:
. /etc/bashrc |
The dot is the source operator. In a nutshell it runs the script within the current shell and any variables created or modified by the script will remain available after the script completes. In your example /etc/bashrc is the system wide global definitions and if the file exists will be loaded in addition to the user definitions in the local bashrc file.
Another example. script1 Code:
#!/bin/bash Code:
#!/bin/bash |
Quote:
When I ran script1 like this: ./script1? It works too. BUT if I try this modification in script1, it fails: Code:
#!/bin/bash Code:
$ test="" What is the difference between "./<some_script1>" and ". <some_script1>" ? |
Code:
man test . means current directory |
Quote:
Code:
Why do I get these error messages? |
./myscript will execute the script and since the permissions do not allow it you see the error message.
As stated in your example the . means current working directory. If you set the permissions for myscript it will execute in a subshell but script1 will display an error because test is undefined. |
|
michaelk & Habitual :
What I am still not able to understand is that when I ran ./myscript, I got a permission denied error. myscript is residing in the same directory as script1. Quote:
Here is better question. Why do i have to "chmod +x myscript" when I ran it like this: Code:
~/dir $ ./myscript #running myscript inside its directory Code:
~/dir $ . myscript |
Because each invocation of 'bash' creates a new shell (+env).
Sourcing via either of Code:
. script.sh (obviously you'll need r perms) This Code:
./script.sh As above, a new shell is a sub-shell (you should google that) and vars+values cannot be 'exported' upwards ie when that shell completes, any var/values created/set within the sub-shell will be wiped. HTH |
chrism01:
Thank you. Below for future reference.... Quote:
Quote:
and inherits from exported variables of current shell. It does not do "reverse" exports of variables back to the script that calls <filename> script. |
this
Code:
. /etc/bashrc Code:
./script.sh . (source or dot operator) |
All times are GMT -5. The time now is 08:13 AM. |