LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 09: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-23-2014, 11:00 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
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, 11:15 AM   #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, 11:24 AM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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, 10: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, 12:28 PM   #6
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
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, 12:29 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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



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 08:04 PM
make: Warning: Both `makefile' and `Makefile' exist ? malli42108 Solaris / OpenSolaris 5 10-24-2009 09: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 06:26 AM
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 03:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:45 AM.

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