The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan UNIX for Dummies Questions & Answers 3 08-02-2008 05:21 PM
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan High Level Programming 1 04-30-2008 01:44 PM
Redirecting to stdin flame_eagle Shell Programming and Scripting 4 02-20-2008 04:25 PM
Capturing stdin domivv Shell Programming and Scripting 3 01-24-2008 04:30 PM
stdin marquis High Level Programming 2 04-14-2005 01:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-28-2006
systemsb systemsb is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 23
echo with stdin

Why doesnt echo output the contents of the file abc.txt as shown below ?

chid@athena:~$ cat abc.txt
sssss
chid@athena:~$ echo < abc.txt

chid@athena:~$
  #2 (permalink)  
Old 09-28-2006
mdhmi mdhmi is offline
Registered User
  
 

Join Date: Sep 2006
Location: Detroit, Michigan
Posts: 23
That is an incorrect usage of "echo".

Do you have something against cat, more, less, page, etc ?
  #3 (permalink)  
Old 09-28-2006
systemsb systemsb is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 23
If stdin opens a file and redirects the content of the file to a command
then echo should work

I know this works

dam@athena:~$ more < abc.txt
sssss

Why then doesnt it work with echo ?
  #4 (permalink)  
Old 09-28-2006
Dhruva's Avatar
Dhruva Dhruva is offline
Registered User
  
 

Join Date: Mar 2006
Location: India
Posts: 255
If you really want to use echo in that way then try this
Code:
xargs echo <filename
Now if you have question regarding xargs then check man page that is really good.
  #5 (permalink)  
Old 09-28-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,355
echo doesn't use stdin !

With ksh you can do :
Code:
echo "$(<abc.txt)"

Jean-Pierre.
  #6 (permalink)  
Old 09-28-2006
srikanthus2002's Avatar
srikanthus2002 srikanthus2002 is offline
Registered User
  
 

Join Date: Sep 2006
Location: Can u guess...!
Posts: 160
[sri]$ echo "$(<just)"
var=sri
for i in 1 2 3 4 5
do
echo "$var.$i"
done

------------------------------

[sri]$ xargs echo <just
var=sri for i in 1 2 3 4 5 do echo $var.$i done

when i use this command xargs it is giving all line in single line as shown above

so i think it would be better to use first example....

i am woundering that we can use echo in different manner..echo "$(<just)"

Thanks ..jenny...
  #7 (permalink)  
Old 09-28-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,909
That is not what echo does. echo prints the commandline arguments it is given, not stdin, not any other file, period. xargs is a workaround that translates things read from stdin into commandline arguments for it, an extra program to join them together. You can limit the number of commands xargs gives to a command like
Code:
xargs --max-args=1 echo < file
But, again, why not just use cat? That's what it's there for.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On



All times are GMT -4. The time now is 09:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0