LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 07-25-2017, 02:54 PM   #1
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237
Blog Entries: 2

Rep: Reputation: Disabled
Bash: ambiguous redirect


Why does echo HelloWorld > * work when I do it from the command line, but when I put it in a script I get an ambiguous redirect error? To clarify I'm redirecting this to 1000 empty files.. Thanks in advanced!

Last edited by justmy2cents; 07-25-2017 at 04:46 PM.
 
Old 07-25-2017, 04:43 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Does it work from an interactive shell (i.e. command line)? You should double check that, I do not think that is correct.

You can do that using the tee command with a glob, but I would suggest using find to generate the list of target files with -exec or xargs would be much safer.
 
Old 07-25-2017, 04:53 PM   #3
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Yeah it works perfectly from the CLI.. I think it has to do with too many open file descriptors, but nevertheless thanks the suggestions ill try em out.

Last edited by justmy2cents; 07-25-2017 at 04:54 PM.
 
Old 07-25-2017, 05:02 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
What distro and shell are you using?
 
Old 07-25-2017, 05:06 PM   #5
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
The machine im trying this on has Xubuntu with the Z shell, but I invoke bash in the shell script.

Last edited by justmy2cents; 07-25-2017 at 05:09 PM.
 
Old 07-25-2017, 05:17 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Quote:
Originally Posted by justmy2cents View Post
The machine im trying this on has Xubuntu with the Z shell.
Then perhaps you should change the title of your question: Bash: ambiguous redirect, as that really increases the ambiguity index!

I am not a zsh user but I see that it does support multiple redirection with a MULTIOS flag. That is not a common shell feature and does not work in Bash, or any other shells I am familiar with.

Please try to keep your question contexts accurate.

Last edited by astrogeek; 07-25-2017 at 05:32 PM. Reason: typos - added original quote context, additional comment.
 
Old 07-26-2017, 10:21 AM   #7
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
You were reading my answer in real-time and I was editing, but anyways thanks dude!
 
Old 07-27-2017, 12:33 PM   #8
justmy2cents
Member
 
Registered: May 2017
Location: U.S.
Distribution: Un*x
Posts: 237

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Quote:
You can do that using the tee command with a glob, but I would suggest using find to generate the list of target files with -exec or xargs would be much safer.
Like so?
Code:
#!/bin/bash
find . -name "*myfiles*" -execdir echo HelloWorld | tee myfiles{1..1000} {} \;
The above doesn't work but this one does, however it also prints onscreen, which it why I think you said it's not safe?
Code:
#!/bin/bash
echo HelloWorld | tee myfiles{1..1000}
Also this doesn't work.
Code:
#!/bin/bash
find . -name "*myfiles*" | xargs echo HelloWorld >

Last edited by justmy2cents; 07-27-2017 at 12:46 PM.
 
  


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
Bash: Ambiguous Redirect in script Firy Programming 4 05-30-2013 08:33 AM
bash returns ambiguous redirect with date in filename rstoutmna Programming 5 09-13-2011 07:37 PM
[SOLVED] bash ambiguous redirect wakatana Programming 2 03-09-2011 09:35 AM
append to end of each file -- -bash: *: ambiguous redirect allele Linux - Software 7 06-03-2009 01:57 PM

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

All times are GMT -5. The time now is 02:01 PM.

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