LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 02-23-2014, 10:24 PM   #1
visionanand
LQ Newbie
 
Registered: Feb 2014
Posts: 3

Rep: Reputation: Disabled
How to look for makefile.


Hi,

I am trying to write a shell script to see if "makefile" is present in a directory. Here is the code.

if [ -a makefile ]; then {

This is giving me an error "test: argument expected". What am i doing wrong here. pls help.

Thanks.
 
Old 02-24-2014, 12:00 AM   #2
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,591

Rep: Reputation: 1244Reputation: 1244Reputation: 1244Reputation: 1244Reputation: 1244Reputation: 1244Reputation: 1244Reputation: 1244Reputation: 1244
Hi,

"-a" is an "and" operator, so test ("[" is one way of running the "test" command) is expecting an argument on its left hand side. You probably want to use the "-e" operator. See the test man page for more information.

HTH,

Evo2.
 
Old 02-24-2014, 12:15 PM   #3
visionanand
LQ Newbie
 
Registered: Feb 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks for the reply. Even when i use "-e" operator I see the same error msg.
 
Old 02-24-2014, 12:24 PM   #4
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 3,222

Rep: Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155
Please post the entire code, chances are there's an error somewhere else. For example, at the end of your snippet you have "then {". That's not the syntax for if statements in BASH.

Code:
if [ -e makefile ]; then
   echo "I found a makefile"
else
   echo "I didn't find a makefile"
fi
 
Old 02-25-2014, 11:17 AM   #5
visionanand
LQ Newbie
 
Registered: Feb 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
The code mentioned above worked in bash shell. i was working in tcsh shell. Im not sure if that caused the issue. Thanks for the help guys.
 
Old 02-25-2014, 01:28 PM   #6
John VV
Guru
 
Registered: Aug 2005
Posts: 13,531

Rep: Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807
Also it might have a CAPITAL M
both
"makefile"
and
"Makefile"
are used

some makefiles ONLY need "make" ran
others NEED options like:
Code:
make -olinux 
make gimp_plugin
make gmic
make test 
make cmake
and some "makefiles" are only a placeholder to run cmake or qmake
i have seen ones that run
Code:
autoreconf -iv
./configure
then
make

you really DO NEED to read that file FIRST
 
Old 02-25-2014, 01:29 PM   #7
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 3,222

Rep: Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155
You can't use bash syntax with the tcsh interpreter.

You can use this reference to change the syntax to tcsh:
http://joelinoff.com/blog/?page_id=235

Or if you want to stick to bash syntax, you should put a
Code:
#!/bin/bash
at the top of your script to force it to use the bash interpreter

http://en.wikipedia.org/wiki/Shebang_(Unix)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] need of makefile info ? how the linux make file is different from simple c makefile ? rpittala Linux - Newbie 2 05-07-2012 09:04 PM
make: Warning: Both `makefile' and `Makefile' exist ? malli42108 Solaris / OpenSolaris 5 10-24-2009 10:09 AM
Is it mandatory to have the name of the makefile as 'Makefile' for kernal module comp narender.d Linux - Kernel 3 05-29-2009 07:26 AM
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 04:57 AM


All times are GMT -5. The time now is 10:57 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration