1755751 Members
3984 Online
108837 Solutions
New Discussion юеВ

Command qns again...

 
SOLVED
Go to solution
Avery_1
Advisor

Command qns again...

1.What is the scope of a local variable?

2.Does the Bourne shell support job suspension and resumption?

3.What other command/commands can one use to list the process running on a machine?

4.What does the echo here outputs?

name="Mike"

export name

echo $name

sh

echo $name

name="Ben"

export name

echo $name

exit

echo $name

:Thanks...
hey
4 REPLIES 4
Balaji N
Honored Contributor
Solution

Re: Command qns again...

hi,

first, i would recommend you to pick up a good book on shell programming and read it. solves most of your queries and gives a good insight.

1. it is available in that shell. when the shell is terminated, the local variable does not exist. all local variables set in this shell are also avaiable by any shells spawned by this shell. (will help u understand q.4)

2. yes. ctrl+z top stop and then fg to start executing it again. actually this ctl+z can be modified. do an stty -a and see the value for susp.

3. ps, top, pstree etc. and if you can manipulate the psuedo file system /proc for information as well.

4. first and second echo will be mike. since you are changing the value after that, the third will be ben and after that the shell exits. so the changed value of name is not available. and name echoes the value of mike again.


hth
-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Avery_1
Advisor

Re: Command qns again...

thanks 4 replying but i am comparing with my answers...that's all...that is y i need u guy's help...i am a newbie in linux...
hey
Balaji N
Honored Contributor

Re: Command qns again...

ph yes. you are welcome.
-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Ramkumar Devanathan
Honored Contributor

Re: Command qns again...

Sophia,

1. local variables declared with the local builtin (bash), are local to the function within which they are defined. They can be declared only within a function. Apart from this, what balaji says holds good for variables defined in the scripts.
function abc()
{
local temp=0 # temp will be local variable in function abc() with local scoping
...
}

2. To add to what Balaji mentions, bg will resume a suspended process in the background.

$ bg

will resume the first of the suspended processes and run it in the background.

3. ps x, ps eaf - man ps generally... also looking at /proc/ is a cool idea, balaji.

4. Nothing to add over what Balaji has added.

HTH.

- ramd.
HPE Software Rocks!