Differenc between print and echo | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Differenc between print and echo

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-11-2007
chandhar chandhar is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 12 April 2007, 5:53 AM EDT
Location: chennai, India
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Java Differenc between print and echo

can anyone explain me what is the difference between echo and print in shell programming?
Sponsored Links
    #2  
Old 04-11-2007
manoj.rana manoj.rana is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 15 January 2008, 2:43 AM EST
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
print and echo

both echo and print are common in working ...
both displays the chars on the screen or windows.
upto me using print we can redirect the output to any file descriptor
using print -u[n] but for echo we have to redirect using redirection operator
or using pipe.
Sponsored Links
    #3  
Old 04-11-2007
Swarna Swarna is offline
Registered User
 
Join Date: Apr 2007
Last Activity: 26 May 2008, 9:50 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
echo & Print

Print - You can format the output
Echo - displys the output as such and it is comparitively faster than print.
    #4  
Old 04-11-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 24 July 2014, 3:12 PM EDT
Location: Ashburn, Virginia
Posts: 9,895
Thanks: 58
Thanked 413 Times in 248 Posts
With ksh at least both echo and print are very fast built-in commands. Dave Korn added print to ksh. At the time ksh was developed Unix was split into a BSD and USG. And the echo statement was different. On BSD, "echo -n" would display no output but on USG it would display "-n". On USG, "echo \\c would display no output, but on BSD it would display "\c". So a portable shell script needed to capture and test the output from "echo -n" and then you could do:
if [ $ECHOTYPE = BSD ] ; then echo -n "enter name - " ; else echo "enter name - \\c" ; fi

Dave felt that rather than trying to solve the echo dichotomy, he would leave "echo" alone and go with "print" which was his own creation. "print" would be the same everywhere. And he added a lot of new stuff to "print".

Later, Posix decreed that the USG echo was standard. And it defined "printf" as a new, more powerful tool. So while Posix encourages the use of "printf", "echo" is now standard too. "print", on the other hand, is a non-standard feature of ksh.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
echo/print variable question riegersteve Shell Programming and Scripting 1 09-02-2010 03:05 PM
Differenc between ps -ef and top Amey Joshi UNIX for Dummies Questions & Answers 2 02-12-2009 12:29 PM
how to print backslah using echo mani_um Shell Programming and Scripting 8 04-12-2007 01:05 PM
echo vs. print PhilW UNIX for Dummies Questions & Answers 1 03-03-2004 11:21 AM
echo or print to screen and file Shakey21 UNIX for Dummies Questions & Answers 2 01-09-2002 06:56 PM



All times are GMT -4. The time now is 02:44 AM.