shell commands

Posted on 2006-04-08
Last Modified: 2013-12-26
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.

Question by:nmretd
    LVL 24

    Accepted Solution

    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)


    Author Comment

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

    LVL 51

    Assisted Solution

    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

    Author Comment

    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.
    LVL 51

    Assisted Solution

    sourced files do not accept arguments (well, not really true: some shells behave different, but i.g. no arguments are read)

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Hibernate methods 2 45
    Smart Camera scanning and reading information 3 76
    modThree challenge 4 53
    post4 challenge 28 70
    Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
    If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now