Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
can anyone tell me how does echo command work internally, i mean hows it display the text we entered, which libraries or files it uses? thankyou! waiting for some good ...
  1. #1
    Just Joined!
    Join Date
    Apr 2009
    Posts
    18

    Unhappy need some help abt echo command

    can anyone tell me how does echo command work internally, i mean hows it display the text we entered, which libraries or files it uses?






    thankyou!
    waiting for some good suggestions.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,970
    Quote Originally Posted by happy-linux View Post
    can anyone tell me how does echo command work internally, i mean hows it display the text we entered, which libraries or files it uses?
    It is a C program that iterates thru the argv[] array and prints to stdout all the arguments passed to it. It probably only needs to use libc for what it does. In all likelihood, it consists of about 10-20 lines of C code. You can always get the source code and see for yourself.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Apr 2009
    Posts
    18

    Red face more on echo

    thankyou for ur useful suggestion.
    now following are some combinations with echo and their outputs, i jst tried randomly, plz tell me what the output are abt........

    1. # echo $-
    himBH (...................what is dis himBH)

    2. #echo $!
    2983 (...................this is not a PID)

    3. #echo $&
    [1]20662
    [root@localhost~]#$
    date;pwd
    sat apr.............. 2009
    [1]+Done echo $
    /root


    let me know what's d significance of $ sign?





    Quote Originally Posted by Rubberman View Post
    It is a C program that iterates thru the argv[] array and prints to stdout all the arguments passed to it. It probably only needs to use libc for what it does. In all likelihood, it consists of about 10-20 lines of C code. You can always get the source code and see for yourself.

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,970
    Quote Originally Posted by happy-linux View Post
    thankyou for ur useful suggestion.
    now following are some combinations with echo and their outputs, i jst tried randomly, plz tell me what the output are abt........

    1. # echo $-
    himBH (...................what is dis himBH)

    2. #echo $!
    2983 (...................this is not a PID)

    3. #echo $&
    [1]20662
    [root@localhost~]#$
    date;pwd
    sat apr.............. 2009
    [1]+Done echo $
    /root


    let me know what's d significance of $ sign?
    Items preceded with a $ are shell or environment variables. They are expanded by the shell before being passed to echo or any other command. The echo command doesn't do anything with them since they are converted first. It only gets the results after expansion. You should read the bash documentation and/or man pages for information about built-in variables, such as ~ or $HOME (the user's home directory), $! (the PID of the last background process), or $- (I don't know - it's the same on my system).
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by Rubberman View Post
    Items preceded with a $ are shell or environment variables. They are expanded by the shell before being passed to echo or any other command. The echo command doesn't do anything with them since they are converted first. It only gets the results after expansion. You should read the bash documentation and/or man pages for information about built-in variables, such as ~ or $HOME (the user's home directory), $! (the PID of the last background process), or $- (I don't know - it's the same on my system).
    More concretely, check for a section called "EXPANSION" in the bash man page. As you very well said, this has nothing to do with echo itself.

    About $-, it's expanded to the current set of options (flags) used to launch bash. It can come in handy sometimes. For example, on a script you could check whether we are on an interactive shell or not by looking for "i" on this string, and you can as well detect if some of the expansions are turned on or off. Some of them might be configurable at run time using the "set" command.

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,970
    Quote Originally Posted by i92guboj View Post
    More concretely, check for a section called "EXPANSION" in the bash man page. As you very well said, this has nothing to do with echo itself.

    About $-, it's expanded to the current set of options (flags) used to launch bash. It can come in handy sometimes. For example, on a script you could check whether we are on an interactive shell or not by looking for "i" on this string, and you can as well detect if some of the expansions are turned on or off.
    Thanks for the info about $-. That was something I was unaware of. Most of my programming is in C, C++, Java, and PL/SQL these days. My last major shell scripting exercises were for korn and C shells back in the 90's, with one exception of a C-shell script I wrote for running a cron'd database archival tool I developed about 4 years ago. I know enough to make functional scripts and tailor my .bash_profile and .bashrc files for my purposes, but I don't use bash to write entire applications as some people do.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #7
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by Rubberman View Post
    Thanks for the info about $-. That was something I was unaware of. Most of my programming is in C, C++, Java, and PL/SQL these days. My last major shell scripting exercises were for korn and C shells back in the 90's, with one exception of a C-shell script I wrote for running a cron'd database archival tool I developed about 4 years ago. I know enough to make functional scripts and tailor my .bash_profile and .bashrc files for my purposes, but I don't use bash to write entire applications as some people do.
    Shell scripts are good for some things. But they are not full blown programming languages, and they are certainly not the best option when it comes to heavy metal regexp stuff or maths unless you resort to an external helper like sed, awk or bc... or when speed matters.

    There are lots of good languages out there, all of them with their own strengths and weaknesses. The best thing about shell scripts is in my opinion that they are easily readable and quick to develop, and that there's a posix compliant shell almost everywhere which allows you to run your script without needing a working compiler.

    But they are certainly not suitable for every case. As the code size grows shell scripts tend to be a bit confusing to read. Then they become what I call "hell scripts"

  8. #8
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,970
    Quote Originally Posted by i92guboj View Post
    As the code size grows shell scripts tend to be a bit confusing to read. Then they become what I call "hell scripts"
    Indeedy! Some program configuration scripts should be taken out and shot, staked, and then burned at the stake!
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  9. #9
    Just Joined!
    Join Date
    Apr 2009
    Posts
    18

    Smile echo

    what can i do more with echo command (by using options, combination of option etc etc.)?


    what is the significance of !# and $- ?

  10. #10
    Linux Guru reed9's Avatar
    Join Date
    Feb 2009
    Location
    Boston, MA
    Posts
    4,651
    Quote Originally Posted by happy-linux View Post
    what can i do more with echo command (by using options, combination of option etc etc.)?


    what is the significance of !# and $- ?
    Check out this thread: http://www.linuxforums.org/forum/lin...o-command.html

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...