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
inline redirect stdin ct2marer UNIX for Advanced & Expert Users 2 09-09-2008 09:50 PM
inline redirect stdin ct2marer Shell Programming and Scripting 5 09-09-2008 09:50 AM
Redirect stdin and out to sockets gyula High Level Programming 1 09-02-2008 10:30 AM
redirect STDIN prkfriryce Shell Programming and Scripting 4 01-04-2007 10:11 AM
stdin not tty when try to pine or redirect Micz UNIX for Dummies Questions & Answers 1 05-20-2004 02:58 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 02-10-2009
metaltree metaltree is offline
Registered User
  
 

Join Date: Feb 2009
Location: Québec city
Posts: 4
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 (permalink)  
Old 02-11-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,257
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 (permalink)  
Old 02-11-2009
metaltree metaltree is offline
Registered User
  
 

Join Date: Feb 2009
Location: Québec city
Posts: 4
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 (permalink)  
Old 02-11-2009
just4fundoit just4fundoit is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 19
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 (permalink)  
Old 02-11-2009
metaltree metaltree is offline
Registered User
  
 

Join Date: Feb 2009
Location: Québec city
Posts: 4
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 (permalink)  
Old 02-11-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
Code:
-bash-3.1$ cat myScript 
#!/bin/bash
cat <(printf "aaa\nbbb\n") <(printf "111\n222\n")
  #7 (permalink)  
Old 02-11-2009
metaltree metaltree is offline
Registered User
  
 

Join Date: Feb 2009
Location: Québec city
Posts: 4
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")'
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 03:12 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