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 ...
- 04-18-2009 #1Just Joined!
- Join Date
- Apr 2009
- Posts
- 18
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.
- 04-18-2009 #2Linux Guru
- 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
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!
- 04-19-2009 #3Just Joined!
- Join Date
- Apr 2009
- Posts
- 18
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?
- 04-19-2009 #4Linux Guru
- 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
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!
- 04-20-2009 #5Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
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.
- 04-20-2009 #6Linux Guru
- 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
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!
- 04-20-2009 #7Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
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"
- 04-20-2009 #8
- 04-21-2009 #9Just Joined!
- Join Date
- Apr 2009
- Posts
- 18
echo
what can i do more with echo command (by using options, combination of option etc etc.)?

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


Reply With Quote
