Cannot redirect to STDIN in a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cannot redirect to STDIN in a shell script
# 1  
Old 02-10-2009
Cannot redirect to STDIN in a shell script

I am unable to use STDIn redirection with < (commands)
When I do the following, both approaches work and give the same results:

1.
Code:
$ printf "aaa\nbbb\n" > file1
$ printf "111\n222\n" > file2
$ cat file1 file2
aaa
bbb
111
222

2.
Code:
$ cat <(printf "aaa\nbbb\n") <(printf "111\n222\n")
aaa
bbb
111
222

However, the second approach won't work when I put in in a script.

I am using Cygwin1.5.25-15

Any clue?
# 2  
Old 02-11-2009
From the manual page of cat:
Code:
...
cat - concatenate files and print on the standard output
...

You should feed the cat with files to hear it purr.
# 3  
Old 02-11-2009
What I don't understand is that the command with < () redirection works perfectly as a single line, but not when included in a script.
# 4  
Old 02-11-2009
Thats the issue with the emulators. Dont get confused, emulators are not real shells, they are made to mimic some of the qualities of shells ! If you try that on a Bash/sh/ksh/csh it will works fine.
-Peace
# 5  
Old 02-11-2009
Thanks, but apparently this goes beyond the Cygwin element.

I tried that on a Linux bash:

1. Works fine as a line:
Code:
-bash-3.1$ cat <(printf "aaa\nbbb\n") <(printf "111\n222\n")
aaa
bbb
111
222

2. Won't work as a script:
Code:
 
-rw-r--r-- 1 cleseb01 cleseb01 51 Feb 11 16:27 script
-bash-3.1$ cat script 
cat <(printf "aaa\nbbb\n") <(printf "111\n222\n")
 
-bash-3.1$ sh script 
script: line 1: syntax error near unexpected token `('
script: line 1: `cat <(printf "aaa\nbbb\n") <(printf "111\n222\n")'

# 6  
Old 02-11-2009
Code:
-bash-3.1$ cat myScript 
#!/bin/bash
cat <(printf "aaa\nbbb\n") <(printf "111\n222\n")

# 7  
Old 02-11-2009
Code:
$ cat script
#!/bin/bash
cat <(printf "aaa\nbbb\n") <(printf "111\n222\n")

Code:
 
$ sh script
script: line 2: syntax error near unexpected token `('
script: line 2: `cat <(printf "aaa\nbbb\n") <(printf "111\n222\n")'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect string from bash stderr to user stdin

Hi there, I need to execute a command in the bash. The program prints some standard (output and) error and then wants the user to choose one of several options and type the according input. I am trying to solve this issue in a bash script but also running into some circular dependency. How can I... (7 Replies)
Discussion started by: fredestet
7 Replies

2. Shell Programming and Scripting

Redirect String to STDIN

Looking for the proper way to bring a string into the stdin. I have a string that I would like to grep and awk. Each have to be run separately, not piped together. So far, the only way I could figure out how is to echo the string and pipe it: echo 'This is my string' | grep my (3 Replies)
Discussion started by: Panman82
3 Replies

3. Shell Programming and Scripting

Shell script to pass multiple stdin to prorgam?

Running on AIX 5.3L. I have a program "foo" written in Fortran that requires 3 levels of inputs from stdin (command prompt). > foo Enter Input 1: a Enter Input 2: b Enter Input 3: c running foo success! > How do I get a shell script to run this automatically? > echo "a" | foo... (2 Replies)
Discussion started by: discoganya
2 Replies

4. UNIX for Dummies Questions & Answers

Redirect stdin stdout to multiple files

Hi, i know how to a) redirect stdout and stderr to one file, b) and write to two files concurrently with same output using tee command Now, i want to do both the above together. I have a script and it should write both stdout and stderr in one file and also write the same content to... (8 Replies)
Discussion started by: ysrini
8 Replies

5. Shell Programming and Scripting

reading from stdin in a shell script

Hello, I've managed to get my .procmailrc file to work. At least it triggers a script which creates a file. But the file is empty. How do I get at the data that's been piped? I've done much creative googling to no avail. I belive it should be in stdin, but I can't figure out how to access... (4 Replies)
Discussion started by: mmesford
4 Replies

6. UNIX for Advanced & Expert Users

inline redirect stdin

Hi: I have the next script on ksh #!/usr/bin/ksh cd $FUENTES qdesign <<-! \$/opt/cognos/ph843e/bin/qtp <<-! \$/opt/cognos/ph843e/bin/quiz <<-! ! ! ! This script is very simple, i want to nest three process quiz into qtp, and this into qdesign. When I run it , i receive the next... (2 Replies)
Discussion started by: ct2marer
2 Replies

7. Shell Programming and Scripting

inline redirect stdin

Hi: I have the next script on ksh #!/usr/bin/ksh cd $FUENTES qdesign <<-! \$/opt/cognos/ph843e/bin/qtp <<-! \$/opt/cognos/ph843e/bin/quiz <<-! ! ! ! This script is very simple, i want to nest three process quiz into qtp, and this into qdesign. When I run it , i receive the... (5 Replies)
Discussion started by: ct2marer
5 Replies

8. Programming

Redirect stdin and out to sockets

For windows was pretty simple to redirect the std in a and out of a child process for "cmd.exe " command prompt terminal to a socket using connected pipes passed to a new process in the STARTUPINFO structure. BOOL b = ::CreatePipe((LPHANDLE)h_stdInRead,(LPHANDLE)hsdtInWriteTmp, &SecAttrib,... (1 Reply)
Discussion started by: gyula
1 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. UNIX for Dummies Questions & Answers

stdin not tty when try to pine or redirect

My supervisor keep getting "stdin not tty" or something like that when he pipe or redirect input into a program. Others don't seem to get this message. Is there some way I can help him to fix or turn this off? Thx in advance (1 Reply)
Discussion started by: Micz
1 Replies
Login or Register to Ask a Question