Operating System - HP-UX
1825759 Members
2241 Online
109687 Solutions
New Discussion

find: missing conjunction

 
SOLVED
Go to solution
Kelli Ward
Trusted Contributor

find: missing conjunction

Hi all,
I have a couple of systems that give me an error when using the find command.

# find . -name whatever*
sh: find: missing conjunction

What variable do I set to allow the system to use wildcards with the find command?
Note: find is the only command I noticed with this error all other commands seem to have no problems with *.

I leave it to those wiser and smarter than myself.

Thanks,
Kel
The more I learn, the more I realize how much more I have to learn. Isn't it GREAT!
14 REPLIES 14
S.K. Chan
Honored Contributor
Solution

Re: find: missing conjunction

Use double quotes .. (example ..)

# cd /var
# find . -name "syslog.*"
A. Clay Stephenson
Acclaimed Contributor

Re: find: missing conjunction

Hi:

The problem is not find but rather that the shell is expanding whatever* into multiple filenames when -name expects 1 argument. The fix is simply to enclose 'whatever*' in single-quotes so that the shell doesn't expand the filenames.
If it ain't broke, I can fix that.
S.K. Chan
Honored Contributor

Re: find: missing conjunction

Also check this .. for more variation to the find command ..

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x0026cbaac6dcd5118ff40090279cd0f9,00.html
Sridhar Bhaskarla
Honored Contributor

Re: find: missing conjunction

Hi Kel,

It is with the shell how it is expaning the wildcards. To get more idea about how it is doing, run a set -x before you execute the find command.

$set -x
$find . whatever*

Look at the command that got executed after the expansion. It will explain your "why".

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Kelli Ward
Trusted Contributor

Re: find: missing conjunction

Thanks for the info.
Since I only have this on some systems, then I presume some shells are set to allow this and some have problems based on (possibly) initial setup. Is it possible to set up a "permanent variable" to allow this during system boot so the command will work without using quotes? Or is this a one time build compiled into the shell with no way to modify.
Thanks for the help.
As always, points to follow.
Kel
The more I learn, the more I realize how much more I have to learn. Isn't it GREAT!
A. Clay Stephenson
Acclaimed Contributor

Re: find: missing conjunction

No Kelli; it is not environment related but simply luck of the draw. If for eaxample you are in a directory with
myfile1
myfile2
myfile3
yourfile

myfile* expands to myfile1, myfile2, and myfile3 but yourfile* simply expands to yourfile.
If it ain't broke, I can fix that.
Kelli Ward
Trusted Contributor

Re: find: missing conjunction

Hi all,

I'm not sure but I think I wasn't clear.
In the find statement I am using, I want it to expand the wildcard and list all files appropriately.

I can go to two different systems, type the exact same command and get two different outputs.

System1:
find / -name *.log
/etc/rc.log
/var/adm/log/syslog.log
(and so on)

System2:
find / -name *.log
sh: find: missing conjunction

I would presume (although this may be too much to ask) if one system can do it. Then the second system can be set/made/prodded/begged/threatened/etc. to do it on a permanent basis. (Unless it is built into the shell itself)

I do not mind modifying my command to force it to work, but I am admittedly curious as to whether or not there is a fix so to speak for this little anomally.

Either that or I think I'm understanding everyone's comments and am not. Heck, I'm open to that too. ;)

Thanks,
Kel
The more I learn, the more I realize how much more I have to learn. Isn't it GREAT!
A. Clay Stephenson
Acclaimed Contributor

Re: find: missing conjunction

Okay Kelli, I'll try one more time. Please do this.

cd /tmp
mkdir tmp1
cd tmp1
cp /dev/null myfile1
cp /dev/null myfile2
cp /dev/null myfile3
cp /dev/null yourfile
ls (you should see all four files listed)

Now let's play with find to list the myfiles:

find . -name 'myfile*'
myfile1
myfile2
myfile3

find . -name 'yourfile*'
yourfile

find itself expands the wildcard pattern matching; we don't want the shell to do it. Maybe this will show you what's wrong:
find . -name myfile* actually appears to the find command as
"find . -name myfile1 myfile2 myfile3" but in order for that syntax to work it would really need to be this:
"find . \(-name myfile1 -o -name myfile2 -o -name myfile3 \)" - the -o means OR

The shell is simply doing what you tell it to do and that is why we want single quotes - no shell expansion.
If it ain't broke, I can fix that.
Kelli Ward
Trusted Contributor

Re: find: missing conjunction

Hi A. Clay,
I believe I understand now.
In other words; (Reader's Digest abridged)
not single quoting the argument causes a conflict (for lack of a better term) between the -name option (wanting to expand the *) and the shell (also wanting to expand the *) using the single quotes tells the shell not to do anything and the -name option is now allowed to do it's work without conflict.

Just curious again.
On my "working" system (The system w/o the missing conjunction statement)something is, I will assume already telling the shell not to expand the *, thus allowing the -name option to be the one to expand it. Do you know what that something is?

Hopefully, I'm not being too annoying. Curiousity is my curse. I can't help myself. For a small consollation I will reward points generously, as much for the good information as for the hard work of pounding it into my thick noggin. :)

Thanks,
Kel
The more I learn, the more I realize how much more I have to learn. Isn't it GREAT!
Darrell Allen
Honored Contributor

Re: find: missing conjunction

Hi Kel,

On your "working" system, how many files are listed when you do "ls *.log"? None I'd guess (assuming your current directory is the same one as when you enter the find command).

How many are listed when you do the same ls command on the system where you get the missing conjunction error? More than 1, right? Again, I'm assuming your current directory is the same as when you enter the find command.

Your issue happens because the shell expands *.log into the list of files in your current directory ending with .log. If you cd into a directory that has no .log files and run your find command (without quoting *.log), it will work. If you have 1 file ending in .log in your current directory, the shell will expand *.log to just that one file name and find will search for files with that name. If you have more than 1 file ending in .log you will get the missing conjunction error.

There is nothing telling the shell to not expand the *. Expansion (perhaps interpretation is a better term) is going to be done by the shell unless you quote what you specify as the argument for -name.

Always quote the arg for -name when it contains a shell metacharacter (wildcard).

Clear as muddy water?

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Deepak Extross
Honored Contributor

Re: find: missing conjunction

Another solution:
Do a "set -f" before running your find command.
"set -f" will turn off filename expansion, and your find command will work as you want.
Deepak Extross
Honored Contributor

Re: find: missing conjunction

Kelli,

This probably answers your question as well:
<< can go to two different systems, type the exact same command and get two different outputs.

System1:
find / -name *.log
/etc/rc.log
/var/adm/log/syslog.log
(and so on)

System2:
find / -name *.log
sh: find: missing conjunct
>>

Methinks, on System1, your .profile/.login has a "set -f" whereas System2 does not.

Hope this exorcises the ghost in the machine.
Darrell Allen
Honored Contributor

Re: find: missing conjunction

Hi again,

Obviously I was wrong that nothing turned off file name expansion in a shell. I didn't know about "set -f". Nice one Deepak!

My answer still holds unless set -f is used in a bourne shell or one of it's derivatives.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Deepak Extross
Honored Contributor

Re: find: missing conjunction

Darrel,

I learned that "trick" from this forum itself. Thanks to Robin.
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xb8c89200caded5118ff40090279cd0f9,00.html
This is why I love this forum!

While on the topic, I must mention that another effect of running a "set -f" is that it turns off filename autocompletion (the esc-esc thingy). If you're as addicted to that escape key as I am, you may want to do a "set +f" to undo the evil effects of the "set -f".