Operating System - HP-UX
1753653 Members
5573 Online
108798 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!