shell commands

Hi Experts,

 I have a couple of questions as I am new to shell programming and I am very much learning now.

1) what is the difference in the command . and sh in executing a shell script. Understand that both executes a sheel script.

2) Understand ps gives the list of process running on the shell. Is there is a command or way to find a particular process whihc is taking lot of memory and keeps on buiding up the memory and blocking other processes from accessing the memory.

Please help me on this. If I come across some other problem , will let you know.

Who is Participating?
fridomConnect With a Mentor Commented:
1) . sources a file within the current instantiation
sh starts a new shell,

2) Obviously you expect that there is one "specialiced" tool for any task, This is as far from the unix way as one can get. You know there is ps so you have to combine it with another tool. Just an example the output of ps -aux looks like this here:
root         1  0.0  0.0   6036   548 ?        S    06:40   0:00 init [3]

You see the different columns? Now you run some tool on this field e.g awk
So we are looking on things where the Mem column is large then 5 MB then print this line

ps aux | awk 'NR > 1 { if ($5> (5 * 1024 * 1024)) { print $0} }'

The power from Unix comes to a very large extend from this facilities to combine diverse methods. Just another example if you want to know how many things are in a directory you probably write somethign like ls * | wc -l
There is no "count entries in directory" there.

what you will have to check are the zillions of optoins for the diverse tools e.g if you want to sort the output ordred by the neede virtual size you write something like:

ps aux --sort %mem or something similiar (not tested)

nmretdAuthor Commented:
Thanks for the reply . caould you please ler me know how is exec command different from . and sh

ahoffmannConnect With a Mentor Commented:
1) . executes the script within the calling shell, all variables in the sourced file are set/changed in the calling shell
   sh starts a new process, anything done there is private to that process and does not effect the calling sh (except permanent changes like files)

2) ps does not show the processes of the shell but of the system!
  see man ps for details (even how to get the amount of memory
  probably you want also use vmstat or top, see man-pages what they provide differnt/additional to ps
nmretdAuthor Commented:
Thanks for the response. I wrote a program to check the number of parametes passed, the script as below (argcheck)

if [ "$#" -ne 2 ]
        echo " Usuage: 2 args expected "
        exit 1

when I executed the above script as '. argcheck' I am not getting any message whihc I am expecting.

I am getting the expected message ' 2 args expected' when I am running it as ' sh argcheck' . Please advise on the 2 different behaviour.

Thanks in advance.
ahoffmannConnect With a Mentor Commented:
sourced files do not accept arguments (well, not really true: some shells behave different, but i.g. no arguments are read)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.