LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-14-2012, 10:07 PM   #1
sarenace
Member
 
Registered: Feb 2012
Posts: 57

Rep: Reputation: Disabled
Problem redirecting to bash shell on cygwin


Hello,
I am working on a windows machine running the cygwin command line interface. I have a spreadsheet that contains references to records kept in a group of text files, from which I need to pull out data. Given that the data set contains >5k references, manually typing out a command for each one is not an option. I figured I could save myself some work by letting the spreadsheet concatenate the commands. This created an output like so:

Quote:
awk 'BEGIN{RS=ORS="\n\n\n}"/80303708953/{print}' HH*txt |awk '/desolada/ && /showed/{print}'
awk 'BEGIN{RS=ORS="\n\n\n}"/80305245858/{print}' HH*txt |awk '/sarenace/ && /showed/{print}'
awk 'BEGIN{RS=ORS="\n\n\n}"/80305597498/{print}' HH*txt |awk '/sarenace/ && /showed/{print}'
awk 'BEGIN{RS=ORS="\n\n\n}"/80307301507/{print}' HH*txt |awk '/bboys777/ && /showed/{print}'
...
...
On my previous fedora system at university, if I had a file full of commands as above, I would type out

Quote:
cat file |/bin/bash
The idea was I would copy the entire lot of commands and type

Quote:
cat /dev/clipboard |/bin/bash
And it failed to work, giving me a heap of syntax errors.

I have tried various solutions using combinations of backquotes, redirecting /dev/clipboard to /dev/stdin and so on; but nothing seems to work. Confusingly, when I copy and paste one command at a time directly into the cygwin shell, it works perfectly!?!? Would anyone have any idea how to fix this?

Last edited by sarenace; 11-14-2012 at 10:42 PM.
 
Old 11-14-2012, 10:27 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
I've never heard of piping a command into /bin/bash, but I understand the problem.

Have you tried something like a read in a loop? Ala:
Code:
while read line; do $line; done < /dev/clipboard

Last edited by suicidaleggroll; 11-14-2012 at 10:35 PM.
 
Old 11-14-2012, 10:35 PM   #3
sarenace
Member
 
Registered: Feb 2012
Posts: 57

Original Poster
Rep: Reputation: Disabled
Just an addendum: Ignore the mistake in the RS value ="\n\n\n}" which should read ="\n\n\n"}; that mistake was made after i had input the commands correctly.

Bash gives the following error message-

' for reading (No such file or directory)

Which I assume means that I'm redirecting this command to a bash shell that opens in the /bin folder? On my previous system when you redirected to |/bin/bash, the process ran in the interactive shell you had open, with all the commands redirected to stdout, as per normal. Perhaps this could be some peculiar environmental variable for cygwin?
 
Old 11-14-2012, 10:41 PM   #4
sarenace
Member
 
Registered: Feb 2012
Posts: 57

Original Poster
Rep: Reputation: Disabled
Thanks for the suggestion suicidaleggroll; unfortunately it didn't work. Still working on it. I cant figure out why on my linux box at university redirection to bash worked so seamlessly and yet on cygwin at home its the devils own job . . .
 
Old 11-16-2012, 09:06 AM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
How about
Code:
. /dev/clipboard
or
Code:
source /dev/clipboard
How did you create the file? What is the output of
Code:
file /dev/clipboard
?
 
Old 11-16-2012, 10:00 AM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
It's probably because /dev/clipboard is using DOS/Windows style line endings, try
Code:
dos2unix < /dev/clipboard | /bin/bash
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl redirecting shell commands ifeatu Programming 3 12-10-2009 11:07 PM
Have you ever used cygwin, i've met a problem with the command stat from cygwin andy820303 Linux - Newbie 0 03-11-2009 03:37 AM
Redirecting output of a shell script raj_deep2k1 Linux - General 2 01-20-2006 07:38 AM
redirecting output in Bourne shell trutnev Linux - Software 2 04-22-2004 03:55 AM
Cygwin:How do you turn the bash shell bell off? petercool Linux - Newbie 8 05-23-2003 10:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration