Saturday, April 18, 2015

Day 14: The Linux Command Line Ch11 Notes


Chapter 11 - The Environment

Commands:
printenv – Print part or all of the environment
set – Set shell options
export – Export environment to subsequently executed programs
alias – Create an alias for a command

Most programs running will use their respective configuration files. Some of them will adjust their behavior using shell variables and environment variables.


Question 1
What does 'set | less' command do?

Question 2
What does 'printenv' command do?

Question 3
Which command can you use to display variable PATH that stores path to executable programs?

Question 4
What is a login shell session?

Question 5
What is a non-login session?

Question 6
Which login session files can Linux read to establish environment?

Question 7
Which startup files a non-login session reads?

Question 8
Which command can you use to display hidden startup files?

Question 9
What does 'export' command do?



ANSWERS

Question 1
What does 'set | less' command do?

It displays both shell and environment variables.

Question 2
What does 'printenv' command do?

It displays only environment variables.

Question 3
Which command can you use to display variable PATH that stores path to executable programs?

$ echo $PATH

or

$ printenv PATH

Question 4
What is a login shell session"?

It is session that prompts us for username and password.

Question 5
What is a non-login session?

It is a terminal session we open from GUI.

Question 6
Which login session files can Linux read to establish environment?

/etc/profile
Script applied to all users

~/.bash_profile
User's personal startup file which can extend or override global configuraition script

~/.bash_login
If ~/.bash_profile is not found, bash will attempt to read this script

~/.profile
If neither of the two previous is found, bash attempts to read this file (debian-based default)


Question 7
Which startup files a non-login session reads?

/etc/bash.bashrc
Global configuration script applied to all users

~/.bashrc
User's personal startup file. It can extend or override global script.

Question 8
Which command can you use to display hidden startup files?

$ ls -a

or 

$ ls -A

Question 9
What does 'export' command do?

Once changes are made in the parent shell, child does not inherit those by default. The command 'export' will allow child shell originated from parent shell to recognize all variable changes.


LAB 6

1. Check the name of your display (number 0 indicates the first display generated by X server). If you're connected via ssh nothing shows.

2. Check the name of your shell program.

3. Check the path to your home directory.

4. Check your terminal type.


LAB ANSWERS

1. Check the name of your display (number 0 indicates the first display generated by X server). If you're connected via ssh nothing shows.

$ printenv DISPLAY

2. Check the name of your shell program.

$ printenv SHELL

3. Check the path to your home directory.

$ printenv HOME

4. Check your terminal type.

$ printenv TERM

Good stuff!