Presentation is loading. Please wait.

Presentation is loading. Please wait.

Compunet Corporation Introduction to Unix (CA263) Your Environment By Tariq Ibn Aziz Dammam Community College.

Similar presentations


Presentation on theme: "Compunet Corporation Introduction to Unix (CA263) Your Environment By Tariq Ibn Aziz Dammam Community College."— Presentation transcript:

1 Compunet Corporation Introduction to Unix (CA263) Your Environment By Tariq Ibn Aziz Dammam Community College

2 Compunet Corporation Objectives In this lecture you will learn –Local variable –Subshells –Exported Variables –PS1 and PS2 –Your PATH

3 Compunet Corporation Objectives In this lecture you will learn –Your Current Directory –More on Subshells –Your.profile File –The TERM Variable

4 Compunet Corporation Local Variables[1] The vartest consists of echo command that display value of x, surrounded by colons $ cat vartest echo :$x: $ x=100 $vartest :: $ vartest doesn’t know about the value of x. Therefore its value is null.

5 Compunet Corporation Local Variables[2] $ cat vartest2 x=50 echo :$x: $ x=100 $vartest2 :50: $ Now question is what is the value of x ? $ echo $x 100 $

6 Compunet Corporation Subshells The behavior exhibited by vartest and vartest2 is due to the fact that these two program are run as subshells by your login shell. When you ask your login shell to execute the vartest, it startup a new shell to execute the program. Whenever new shell runs it runs in its own environment with its own set of local variables. A subshells has no knowledge of local variables that were assigned values by the login shell. A subshell cannot change the value of a variable in the parent shell.

7 Compunet Corporation Exported Variables There is a way to make the value of a variable known to a subshell, and that’s by exporting it with the export command. Here is a program vartest3 $ cat vartest3 echo x = $x echo y = $y $ $ x=100 $ y=10 $ vartest3 x = y = $ export y $ vartest3 x = y = 10 $

8 Compunet Corporation Exported Variables Change the value of x and y in vartest4. $ cat vartest4 x=50 y=5 $vartest4 $echo $x $y 100 10 $

9 Compunet Corporation Exported Variables $ cat vartest4 x=50 y=5 z=1 export z Vartest5 $ $cat vartest5 echo x = $x echo y = $y echo z = $z $ $ vartest4 x= y=10 z=1 $ When vartest4 get executed, the exported variable y will be copied into the subshell’s environment. vartest4 set the value of x, y and z. The it export z. This makes the value of z accessible to any subshell.

10 Compunet Corporation Exported Variables Example $ cat vartest4 x=50 y=5 z=1 export y z vartest5 $ $cat vartest5 echo x = $x echo y = $y echo z = $z $ If you change the vartest4 to explicitly export the value of y, then changed value of y will get exported down to vartest5. $ vartest5 x= y=5 z=1 $

11 Compunet Corporation export with No argument If you just type export, not followed by any argument, you will get a list of the exported variables that are exported by your shell. export LOGNAME export PATH export TIMEOUT export TZ export y

12 Compunet Corporation PS1 and PS2 The characters that the shell display as your command prompt are stored in the variable PS1. You can change this variable to be anything you like. $ echo :$PS1: :$ : $ PS1="==>“ ==>

13 Compunet Corporation PS1 and PS2 Your secondary command prompt, normally > is kept in the variable PS2, where you can change it as you like. $ echo :$PS2: :> : $ PS2="=====>” $ $ for x in 1 2 3 =====> do =====> echo $x =====> done 1 2 3 $

14 Compunet Corporation HOME variable Your home directory is where you are placed whenever you log onto the system. A special variable HOME is also automatically set to this directory when you log on. $ echo $HOME /usr/steve $ HOME=/usr/steve/book $ pwd /usr/steve $ cd $ pwd /usr/steve/book

15 Compunet Corporation Your PATH Whenever you type in the name of a program to be executed, the shell searches a list of directories until it find the program. The list of directories is contained in a special variable called PATH $ echo $PATH /bin:/usr/bin: You can always override the path variable by specifying the path to the file to be executed.

16 Compunet Corporation Example PATH The shell will go directly to /bin to execute date. $ /bin/date Or./rolo You can execute rolo without specifying path if the directory of rolo is specified in PATH variable.

17 Compunet Corporation Your Current Directory $ cat cdtest cd /usr/steve/bin pwd $ pwd /usr/steve $ cdtest usr/steve/bin $ pwd /usr/steve Why we are in /usr/steve where as we changed the directory in cdtest program?

18 Compunet Corporation CDPATH Variable The CDPATH variable works like the PATH variable. It specifies a list of directories to be searched by the shell whenever you execute the cd command. This search is done only if the specified directory is not given by a full path name and if CDPATH is not null.

19 Compunet Corporation CDPATH Variable Example If you type cd /usr/steve then the shell changes your directory directly to /usr/steve But if you type cd memos, then shell will look at your CDPATH variable to find the memo directoy. And if the CDPATH looks like this $ echo $CDPATH :/usr/steve:/usr/steve/docs $ cd /usr/steve $ cd memos /usr/steve/docs/memos $ cd bin /usr/steve/bin

20 Compunet Corporation More on Subshells $ cat vars BOOK=/usr/steve/book UUPUB=/usr/spool/uucppublic DOCS=/usr/steve/docs/memos DB=/usr2/data $ $ vars $ echo $BOOK $

21 Compunet Corporation The. Command There is a shell built-in command called. (dot). file Whose purpose is to execute the content of file in the current shell. $. vars $ echo $BOOK /usr/steve/BOOK $

22 Compunet Corporation The.profile Command Your login shell executes two special files on the system. The first is /etc/profile. This file is set up by the two system administrator and usually does things like checking to see if you have mail. The second file that get automatically executed is.profile in your home directory. Your system administrator may have given you a default.profile file when you got your account.

23 Compunet Corporation The.profile Command $ cat $HOME/.profile PATH="/bin:/usr/bin:/usr/lbin::" export PATH $

24 Compunet Corporation The TERM Variable If you tend to use more than one type of terminal, then the.profile is a good place to put some code to prompt for the terminal type and then set the TERM variable accordingly. A sample code from.profile file on next slide.

25 Compunet Corporation The TERM Variable echo "what terminal are you using(hp-2621 is default ?\c" read TERM if [ -z "$TERM" ] then TERM=2621 fi export TERM


Download ppt "Compunet Corporation Introduction to Unix (CA263) Your Environment By Tariq Ibn Aziz Dammam Community College."

Similar presentations


Ads by Google