LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ambiguous redirection question. (https://www.linuxquestions.org/questions/linux-newbie-8/ambiguous-redirection-question-4175460105/)

sysmicuser 04-30-2013 12:21 AM

ambiguous redirection question.
 
Guys,

I have a simple question.

I am doing two "finds" and first one works fine without any question however for the second one I am getting error like "ambiguous redirect" .

Well this is becoming an interesting thing as the syntax is fine and don't think there is any issue with that.

First find statement.
Code:

find ${BASE_DIRECTORY} -path \*/input/* -type f -not -wholename "*/unused/*" -mmin +60 -print >> ${INPUT_FILES}
Second find statement.
Code:

find ${BASE_DIRECTORY} -path \*/error/* -type f -not -name "SS*" -not -name "AA*" -not -name "PQ*" -mmin +60 -print >> ${ERR0R_FILES}
So may i know why is the second statement giving us the grief?

grail 04-30-2013 03:19 AM

Try saying the second one out loud ... I think you will find there is a word missing between each 'not name' combo.

I would also be curious why you want the first asterisk not interpreted but then leave the second raw for the -path argument??

sysmicuser 04-30-2013 04:53 AM

I used 2>&1 | tee -a ${LOGFILE} and error disappeared. I don't think there is any word missing between "-not -name "AA*
as I believe that is what the syntax is? Moreover If I run the same command in shell it works fine except in shellscript.

I could not understand your second question.

Quote:

I would also be curious why you want the first asterisk not interpreted but then leave the second raw for the -path argument??

sysmicuser 04-30-2013 04:57 AM

I now understood your second question. For path, all I want is all is all those files which match following pattern.
Code:

h1/input/h2
f1/f2/f3/input/f3
f1/f2/f3/input/f4
f1/f2/f3/input/f5

meaning let there any no of directories/files before input and after input directory, I only want those files which are coming after "input" directory. make sense now?

whizje 04-30-2013 05:20 AM

Adding quotes around the variable seems to be a good way to deal with the "ambiguous redirect" message: You tend to get a better message when you've made a typing mistake -- and when the error is due to spaces in the filename, using quotes is the fix.
Code:

bash-4.2$ find ${BASE_DIRECTORY} -path \*/error/* -type f -not -name "SS*" -not -name "AA*" -not -name "PQ*" -mmin +60 -print >> "${ERR0R_FILES}"
bash: : No such file or directory


shivaa 04-30-2013 05:29 AM

Quote:

Originally Posted by sysmicuser (Post 4941746)
I now understood your second question. For path, all I want is all is all those files which match following pattern.

No. Grail's question was that why you used escape character i.e. \ (backslash) before first asterisk symbol in error, while you didn't escaped the trailing asterist symbol? You did:
Code:

... -path \*/error/*  ...
Whereas Grail asked that why you didn't do this:
Code:

... -path \*/error/\* ...
Quote:

I used 2>&1 | tee -a ${LOGFILE} and error disappeared.
You have just redirected the std error, but error is still there.

However, once invoke command without redirecting it's output to a file, and check where you're getting error:
Code:

~$ find ${BASE_DIRECTORY} -path \*/error/* -type f -not -name "SS*" -not -name "AA*" -not -name "PQ*" -mmin +60 -print
I doubt, the ambiguous redirect error is because of multiple -not options that you've used. (Though I do not have a Unix system available, so I couldn't verify it).

whizje 04-30-2013 05:32 AM

Check if ${ERR0R_FILES} exists and else first create it. The find command works fine here.

shivaa 04-30-2013 07:39 AM

Quote:

Originally Posted by whizje (Post 4941765)
Check if ${ERR0R_FILES} exists and else first create it. The find command works fine here.

Its not necessory to file ${ERR0R_FILES} already exist. It will be created automatically. Both commands are running fine. So it seems some pb with OP's working shell.

@OP:
Can you once try following, without closing variable name in curly braces, as follow:
Code:

find $BASE_DIRECTORY -path \*/error/* -type f -not -name "SS*" -not -name "AA*" -not -name "PQ*" -mmin +60 -print >> $ERR0R_FILES

grail 04-30-2013 09:52 AM

My bad on my first point ... it just seemed there should be some and's or or's in between the not's. I am guessing this is somehow implied as an and in this case.

And yes shivaa pointed out my curious question correctly. Personally I would have just used single quotes as escaping gives me the yips.

rknichols 04-30-2013 09:58 AM

As was suggested by whizje, the "ambiguous redirect" error is very likely due to the unquoted variable ERROR_FILES containing embedded white space in its value. I can easily reproduce the behavior that way:
Code:

$ ERROR_FILES="bad files"
$ echo hello >>${ERROR_FILES}
bash: ${ERROR_FILES}: ambiguous redirect
$


whizje 04-30-2013 03:06 PM

Quote:

Its not necessary to file ${ERR0R_FILES} already exist. It will be created automatically. Both commands are running fine. So it seems some pb with OP's working shell.
I should be more precise in my writing. I meant check if ERROR_FILES contains a value and is not empty.

sysmicuser 05-02-2013 10:54 PM

@grail

I don't think so there is anything missing between -not -name "PQRS*" I believe this is the syntax, anything wrong here?

sysmicuser 05-03-2013 04:19 AM

@whizje

I did try " around the variable name but that didn't worked not sure why.

sysmicuser 05-03-2013 04:22 AM

@shivaa

Why you suggest the original quote without curly brace? normally we use variable in dollar with curly braces right?

Please advise.

Thanks.

sysmicuser 05-03-2013 04:40 AM

@shivaa

Quote:

You have just redirected the std error, but error is still there.
So if there is any error, forget about that error how should we capture it? I believe

Code:

2>&1 | tee -a ${LOG_FILE}
Captures pretty much any error? I want to capture any error and end the script there and there itself instead of proceeding further.


All times are GMT -5. The time now is 04:50 PM.