Difference between revisions of "Centos Bash Shell Scripts"

From rbachwiki
Jump to navigation Jump to search
Line 16: Line 16:
The BASH runtime configuration files (/etc/bashrc and ~/.bashrc) are typically used to set aliases and variables that must be present in the BASH shell. They are executed immediately after a new login as well as when a new BASH shell is created after login. The /etc/bashrc file contains aliases and variables for all users on the system, whereas the ~/.bashrc file contains aliases and variables for a specific user. <br />
The BASH runtime configuration files (/etc/bashrc and ~/.bashrc) are typically used to set aliases and variables that must be present in the BASH shell. They are executed immediately after a new login as well as when a new BASH shell is created after login. The /etc/bashrc file contains aliases and variables for all users on the system, whereas the ~/.bashrc file contains aliases and variables for a specific user. <br />
The other environment files are only executed after a new login. The /etc/profile file is exe- cuted after login for all users on the system and sets most environment variables, such as HOME and PATH. After /etc/profile finishes executing, the home directory of the user is searched for the hidden environment files. bash_profile, .bash_login, and .profile. If these files exist, the first one found is executed; as a result, only one of these files is typically used. These hidden environment files allow a user to set customized variables independent of BASH shells used by other users on the system; any values assigned to variables in these files override those set in /etc/profile, /etc/bashrc, and ~/.bashrc due to the order of execution
The other environment files are only executed after a new login. The /etc/profile file is exe- cuted after login for all users on the system and sets most environment variables, such as HOME and PATH. After /etc/profile finishes executing, the home directory of the user is searched for the hidden environment files. bash_profile, .bash_login, and .profile. If these files exist, the first one found is executed; as a result, only one of these files is typically used. These hidden environment files allow a user to set customized variables independent of BASH shells used by other users on the system; any values assigned to variables in these files override those set in /etc/profile, /etc/bashrc, and ~/.bashrc due to the order of execution
[[File:Escape sequence.jpg|thumb|Escape Sequence]]
==Structure of a bash Script==
==Structure of a bash Script==
  #!/bin/bash  
  #!/bin/bash  
Line 27: Line 28:
  fi
  fi


[[File:Escape sequence.jpg|thumb|Escape Sequence]]
 
[[File:Test Statements.jpg|thumb|Test Statements]]
[[File:Test Statements.jpg|thumb|Test Statements]]

Revision as of 20:59, 7 March 2019

List Environment Variables

set
# you can | to grep to filter
or
env

Environmental Files

Files that execute each time a user logs in to bash shell

/etc/profile 
/etc/bashrc 
~/.bashrc 
~/.bash_profile 
~/.bash_login 
~/.profile

The BASH runtime configuration files (/etc/bashrc and ~/.bashrc) are typically used to set aliases and variables that must be present in the BASH shell. They are executed immediately after a new login as well as when a new BASH shell is created after login. The /etc/bashrc file contains aliases and variables for all users on the system, whereas the ~/.bashrc file contains aliases and variables for a specific user.
The other environment files are only executed after a new login. The /etc/profile file is exe- cuted after login for all users on the system and sets most environment variables, such as HOME and PATH. After /etc/profile finishes executing, the home directory of the user is searched for the hidden environment files. bash_profile, .bash_login, and .profile. If these files exist, the first one found is executed; as a result, only one of these files is typically used. These hidden environment files allow a user to set customized variables independent of BASH shells used by other users on the system; any values assigned to variables in these files override those set in /etc/profile, /etc/bashrc, and ~/.bashrc due to the order of execution

Escape Sequence

Structure of a bash Script

#!/bin/bash 
echo -e "Today’s date is: \c" 
date echo –e "\nThe people logged into the system include:" 
who 
echo –e "\nWould you like to see the contents of /?(y/n)--> \c" 
read ANSWER if [ $ANSWER = "y" ] 
then echo –e "\nThe contents of the / directory are:" 
ls –F / 
fi


Test Statements