nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

echo command

This is a discussion on echo command within the Shell scripting forums, part of the Development/Scripting category; can anyone tell me how does echo command work internally, i mean hows it display the text we entered, which ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 27-04-2009, 12:19 PM
Junior Member
User
 
Join Date: Apr 2009
OS: RHEL5
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
gr8linux is on a distinguished road
Smile 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?
Reply With Quote
  #2 (permalink)  
Old 29-04-2009, 07:21 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,709
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Do you know C programming? Otherwise it will be pretty hard to understand. On other hand you can list all used libraries with the following command:
Code:
ldd /bin/echo
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 29-04-2009, 08:42 PM
Junior Member
User
 
Join Date: Apr 2009
OS: RHEL5
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
gr8linux is on a distinguished road
Wink

Quote:
Originally Posted by nixcraft View Post
Do you know C programming? Otherwise it will be pretty hard to understand. On other hand you can list all used libraries with the following command:
Code:
ldd /bin/echo

yup, i know d C programming...... r u going to gv me its coding?
gr8, welcome for ur answers......
i tried this command, shows the depedencies, but the echo command can work without these files, then how can they be depandency files for echo?
Reply With Quote
  #4 (permalink)  
Old 29-04-2009, 09:15 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,709
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

No it cannnot run. Your shell finds them and load those file at run time using loader. There is always a program called ld.so and ld-linux.so* which find and load the shared libraries needed by a program such as /bin/echo, prepare the program to run, and then run it.

Almost all linux / UNIX / BSD binaries require dynamic linking. The shared libraries needed by the program are searched for in various places such as /lib, /lib64, /usr/lib and so on. One can also set LD_LIBRARY_PATH. Also, /etc/ld.so.cache file contains a compiled list of candidate libraries previously found in the augmented library path.

The dynamic linker can be run either indirectly through running some dynamically linked program or library directly by running as follows:

Code:
/lib/ld-linux.so.* /bin/echo "Welcome"

I suggest you get Linux kernel programming book. It will explain everything about kernel, loader and much more.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #5 (permalink)  
Old 29-04-2009, 09:25 PM
Junior Member
User
 
Join Date: Apr 2009
OS: RHEL5
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
gr8linux is on a distinguished road
Smile

thankyou very much for ur suggestion. i m doing a research on echo command for my office..... so if u know more abt echo command.... plz tell me , like what can echo do other then displaying text msg.... and many more.....




thnx once again
Reply With Quote
  #6 (permalink)  
Old 30-04-2009, 12:53 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,709
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Yes, read the man page for all options:
Code:
man echo
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #7 (permalink)  
Old 30-04-2009, 08:49 AM
Junior Member
User
 
Join Date: Apr 2009
OS: RHEL5
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
gr8linux is on a distinguished road
Thumbs up

Quote:
Originally Posted by nixcraft View Post
Yes, read the man page for all options:
Code:
man echo
already tried the options by man page, setting background and foreground colour, setting effects....

can u plz tell me what is himBH ?
when i typed command as:
# echo $-
himBH


and it is the same in all system where RHEL5 is running.......
Reply With Quote
  #8 (permalink)  
Old 30-04-2009, 10:26 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,709
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default BASH Special Parameters

It is a special parameter and it is used by bash shell. echo command it used to print the value of $-. A hyphen expands to the current option flags as specified upon invocation, by the set built-in command, or those set by the shell itself (such as the -i). Each character represent set values of shell options. For e.g.
  • h = history on
  • i = allow comments to appear in interactive commands
  • m = Job control is enabled
  • B = the shell will perform brace expansion
  • H = Enable ! style history substitution.

See bash man page (look for Special Parameters section) and set command help page:
Code:
help set
man bash
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #9 (permalink)  
Old 09-05-2009, 05:14 PM
Junior Member
User
 
Join Date: Apr 2009
OS: RHEL5
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
gr8linux is on a distinguished road
Default

Quote:
Originally Posted by nixcraft View Post
It is a special parameter and it is used by bash shell. echo command it used to print the value of $-. A hyphen expands to the current option flags as specified upon invocation, by the set built-in command, or those set by the shell itself (such as the -i). Each character represent set values of shell options. For e.g.
  • h = history on
  • i = allow comments to appear in interactive commands
  • m = Job control is enabled
  • B = the shell will perform brace expansion
  • H = Enable ! style history substitution.
See bash man page (look for Special Parameters section) and set command help page:
Code:
help set
man bash
thankyou buddy .
echo has a option in man page ie \r for carriage return, what does it mean actually? can u plz gv me some examples to clear it out...
Reply With Quote
  #10 (permalink)  
Old 19-05-2009, 04:22 AM
Member
User
 
Join Date: May 2009
OS: Mandriva
Posts: 78
Thanks: 0
Thanked 14 Times in 14 Posts
Rep Power: 2
cfajohnson has a spectacular aura about cfajohnson has a spectacular aura about
Default

Quote:
Originally Posted by gr8linux 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?

echo is a builtin command. Get the source code for bash at ftp://ftp.gnu.org/gnu/bash/.

However, for most purposes, it is better to use printf (also a builtin).
Reply With Quote
Reply

Tags
echo , ldd , shell $- variable , shell scripting , shell special parameters


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
UNIX / Linux echo command examples raj Getting started tutorials 8 15-11-2009 02:18 AM
save command and command output savook CentOS / RHEL / Fedora 1 08-05-2009 05:33 PM
How to echo with colors? eawedat Shell scripting 3 29-04-2009 08:47 PM
Automate command execution - reboot-command execution ganeshp@moris.org Shell scripting 2 03-12-2008 11:18 AM
displaying the executed command then echo the status warren Shell scripting 4 29-11-2006 01:56 AM


All times are GMT +5.5. The time now is 02:09 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38