Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > BOOK Beginning Linux Programming, 3rd Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK Beginning Linux Programming, 3rd Edition
This is the forum to discuss the Wrox book Beginning Linux Programming, 2nd Edition by Richard Stones, Neil Matthew, Alan Cox; ISBN: 9780764543739
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK Beginning Linux Programming, 3rd Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 25th, 2004, 01:45 AM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compiled error of executing chapter2 source code

: command not found
: command not found
'irst: line 9: syntax error near unexpected token `do
'irst: line 9: `do

Above words are the error msg after I run the command "/bin/sh first"
which showed on page 26.

Please help me out!

William

  #2 (permalink)  
Old September 25th, 2004, 10:44 AM
Registered User
 
Join Date: Sep 2004
Location: Brooklyn, NY, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did you type the source code for 'first' from scratch? If so, check for typing errors.

The error message is directing your attention to line 9. Usually -- but not always -- the error will be found in line 9 or the one immediately preceding.

Copy-and-paste the code you actually tried to compile -- not just the error message you got. It makes it a lot easier for others to help out in diagnosis.

Jim Keenan


Just Another Perl Hacker
  #3 (permalink)  
Old September 26th, 2004, 05:53 PM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default


The source code I used is downloaded from wrox website directly, and I did not modify any single word of them.
So I think that it is not typing error.
Any possible error in this case?




  #4 (permalink)  
Old September 26th, 2004, 05:56 PM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

#!/bin/sh

# first
# This file looks through all the files in the current
# directory for the string POSIX, and then prints the name of
# those files to the standard output.

for file in *
do
  if grep -q POSIX $file
  then
    echo $file
  fi
done

exit 0


Above it is the source code I copied from my source code folder


  #5 (permalink)  
Old September 27th, 2004, 04:27 AM
Registered User
 
Join Date: Jul 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

I don't have the book nearby, but I wrote the script from scratch and didn't find any mistakes, listing my home directory and pointing the one file with the word POSIX... the script itself ;).
Try to make it executable (even though there isn't any problem with /bin/sh first):
$ chmod u+x first
$ ./first

Ari Constancio

  #6 (permalink)  
Old March 3rd, 2005, 03:44 PM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by williamlin
 : command not found
: command not found
'irst: line 9: syntax error near unexpected token `do
'irst: line 9: `do

Above words are the error msg after I run the command "/bin/sh first"
which showed on page 26.
William, I get exactly the same error message when running Knoppix 3.7 as either 'root' or any other user! Running it under Ubuntu's "Warty Warthog" (another 'debian-based' Linux version) is also exactly the same! Now, notice this very similar, but not exactly the same output:
Code:
: command not found
: command not found
'irst: line 9: syntax error near unexpected token `
'irst: line 9: `
I got this after placing a blank line between the one with "for files in *" and the "do" line. HOWEVER, that's far from the end of my testing! If you set the "first" script's permissions to be an executable file, and ENTER it like this: ./first, then I end up getting this error message:
Code:
: bad interpreter: No such file or directory
What makes this so frustrating is the fact that I got the whole thing to work just fine when ENTERING the commands line by line as shown in the book; well, actually the book shows a slight variation of "first" but I then entered "first"'s lines and yes, it does work that way! I'm going to try running this in a completely different version of Linux and see if its "bash" is acting the same way... later...

The Starman
http://thestarman.dan123.com/
  #7 (permalink)  
Old March 3rd, 2005, 05:15 PM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, here I am under Red Hat 9.0 Linux, and I'm getting the same very frustrating error for other scripts in chapter 2 as well:
Code:
$ ./first
: bad interpreter: No such file or directory
$ ./_if
: bad interpreter: No such file or directory
Yet, if I enter it similar to what the author showed us on page 24, like this:
Code:
$ for file in *
> do
> if grep -q POSIX $file
> then
> echo $file
> fi
> done
first
README
You can see that it lists the two files in the 'chapter02' directory that contain the word "POSIX"! And if I use the command history, it comes up like this and still works fine:
Code:
$ for file in *; do if grep -q POSIX $file; then echo $file; fi; done
first
README
It also acts the same way if I go into 'sh' :
Code:
sh-2.05b$ ./first
: bad interpreter: No such file or directory
So, does anyone know what's going on with all of these Linux OS Shell's not working the way the author expected?!?!?
:(
I just finally figured out what has been causing this problem! And boy am I mad at the last person to have touched the author's code files, especially if it was one of them, since they should know better: ALL THE FILES WERE FILLED WITH DOS/WINDOWS NEW LINE PAIRS (0xA 0xD) INSTEAD OF just the Linux/UNIX single New Line character! After converting them to Linux new line files, all should work fine!
   This was something I certainly didn't expect with a book only about Linux/UNIX!
    I wonder what M$ windoze only guy at WROX did this to us? ;)

The Starman
http://thestarman.dan123.com/
  #8 (permalink)  
Old March 4th, 2005, 08:35 AM
Registered User
 
Join Date: Jul 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

Interesting... That's why I said it was working - I typed it all and didn't use any code.

Ari Constâncio

  #9 (permalink)  
Old December 12th, 2005, 01:54 PM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you need to change mdos formatted text to unix/linux format

open the msdos text file in vi and type the following commands:

: set fileformat=unix
: wq

Why oh why are the download files formatted in msdos ?

All Begineers need help not hurdles.



  #10 (permalink)  
Old June 7th, 2006, 09:33 PM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just wanted to say that this post got me over my first hurdle. How do you contact wrox to make them change the msdos newline? i'll have to do it for every sample i downloaded from them and want to try...

 


Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Source Code in Chapter 16 Lcstyle BOOK: Beginning Linux Programming, 4th Edition ISBN 978-0-470-14762-7 1 February 28th, 2009 09:14 AM
Error on source code 7-51? fedrok BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 1 October 15th, 2008 10:51 AM
error(compiled by vc6.0) in the sample ? tostar BOOK: Professional C++ 1 August 23rd, 2008 02:55 AM
Error in source code compiling angelika J2EE 2 December 29th, 2003 10:45 AM



All times are GMT -4. The time now is 12:11 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.