echo with stdin


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting echo with stdin
# 1  
Old 09-28-2006
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  
Old 09-28-2006
That is an incorrect usage of "echo".

Do you have something against cat, more, less, page, etc ?
# 3  
Old 09-28-2006
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  
Old 09-28-2006
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  
Old 09-28-2006
echo doesn't use stdin !

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


Jean-Pierre.
# 6  
Old 09-28-2006
[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  
Old 09-28-2006
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

STDIN and STDOUT

Hallo, i have a script like: if ;then echo "OK" else echo "ERROR $2 is missing" fi; if ;then touch $2 fi; if ;then cat $1 | grep xy > $2 (1 Reply)
Discussion started by: eightball
1 Replies

2. Shell Programming and Scripting

STDIN-perl

Good morning! How do I make the info that someone inputs from @userArray = <STDIN>, a new array? @userArray = <STDIN>; while () { chomp; last if ! /\d/; push(@userArray,$_); } my($sum,$avg) = &sumIt(@userArray); print "Total:$sum\nAverage:$avg\n"; Im... (2 Replies)
Discussion started by: bigben1220
2 Replies

3. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

4. UNIX for Dummies Questions & Answers

fork and stdin

When a process fork(), the child share the same file descriptors as his father. Thus, they share the same stdin. Quick and dirty exemple below (sorry for the ugly gets() call) : #include <stdio.h> #include <unistd.h> int main() { char buf; if (fork()) { /*parent */ ... (1 Reply)
Discussion started by: milouz
1 Replies

5. UNIX for Dummies Questions & Answers

How to write to stdin of another program (program A -> [stdin]program B)

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question: ---------... (3 Replies)
Discussion started by: vvaidyan
3 Replies

6. Programming

How to write to stdin of another program (program A -> [stdin]program B)

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question: ---------... (1 Reply)
Discussion started by: vvaidyan
1 Replies

7. Shell Programming and Scripting

Redirecting to stdin

Hi, I'm having trouble with my script. I have to select different choices without any interaction from a menu that looks like : a - xxxxxxxxxxxxxx b - xxxxxxxxxxxxxx c - xxxxxxxxxxxxxx d - xxxxxxxxxxxxxx I tried things like : echo "a" >&0 read < echo "a" but none worked. Any... (4 Replies)
Discussion started by: flame_eagle
4 Replies

8. Shell Programming and Scripting

Capturing stdin

Hi all, Consider the following situation: - you launch an compiled binary application from inside a unix shell which presents a text-based type user interface where you can input information ... # echo "I am the $SHELL shell" # I am the /bin/bash shell # ./input # ... imagine the binary... (3 Replies)
Discussion started by: domivv
3 Replies

9. Shell Programming and Scripting

redirect STDIN

can you redirect STDIN with command arguments? I have tried this approach: # ./script -option <argument1> <argument2> 0<$2 # $2: ambiguous redirect Is this possible? (4 Replies)
Discussion started by: prkfriryce
4 Replies

10. Programming

stdin

hi, how does a program know whether some data are available from stdin? I would like to make a program which could read its data from stdin and _if_there_is_nothing_at_stdin_ from a file which name is given as an argument. If there is nothing in stdin and no filename is given as argument,... (2 Replies)
Discussion started by: marquis
2 Replies
Login or Register to Ask a Question