Fedora Linux Support Community & Resources Center
  #1  
Old 1st June 2011, 09:29 PM
pakito15191 Offline
Registered User
 
Join Date: Jun 2011
Posts: 7
linuxchrome
Compiling and running in terminal at the same time

Hello to everyone
This is my first post here, I'm new in Fedora and I came some weeks ago from Ubuntu (since Fedora 15 beta was available)
I like to program sometimes, and in Ubuntu I just used gedit and a little script I did that worked pretty well with my C files, as I didn't like too much the compilers and I love the gedit syntax

I wrote this (at the beginning of the C source code):
Code:
/*
#!/bin/bash
gcc program.c -o program -lm
./program
*/
And I just had to double click the source file (ofc I gave it "Execution permission" ages ago), select "Run in terminal" and it did all itself, giving me the program from just that, from the source code

Here, if I follow the normal steps to compile the program manually, it works perfectly, but if I try this script, it gives me the following error:
/home/user/Program/program.c: line 1: /bin: Is a directory

I know it's shouldn't be right at all to execute a bash script from a .c code that then compiled itself, but it used to work, so I was wondering where is the difference

I have gcc installed and "which bash" gives me the "/bin/bash", so I think that's right
Also, I'm using the stable version of Fedora 15, and I post this question because I didn't find the answer anywhere
Thank you so much!
Reply With Quote
  #2  
Old 2nd June 2011, 03:33 AM
Dies Offline
Registered User
 
Join Date: Oct 2006
Posts: 4,752
linuxubuntufirefox
Re: Compiling and running in terminal at the same time

I thought the "shebang" had to be on the first line. I definitely wouldn't have expected it to work sandwiched between C-style comments...

I guess you're right though it *sort* of works on Ubuntu.

Code:
~$ ./test.sh 
./test.sh: line 1: /bin: is a directory
This shouldn't work!
./test.sh: line 4: Desktop/: is a directory
For whatever reason it still ran my "echo" line.
Reply With Quote
  #3  
Old 2nd June 2011, 06:27 PM
stevea's Avatar
stevea Online
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,300
linuxfedorafirefox
Re: Compiling and running in terminal at the same time

DIes is right - the pound-bang "#!" as the VERY FIRST characters of a file are interpreted in the kernel exec.
Putting that in on the second line is meaningless.

Since the file is executable and not a recognized binary format it is still exec'ed in the shell.
The first line "/*" is interpretted as a bash shell command. On my root file system "/* expands to ...
/bin /boot /cgroup /common /dev /etc /home /lib /lib64 /lost+found /media /mnt /null /opt /opt2 /proc /root /sbin /selinux /
and when the shell attempts to execute this - then it complains that /bin is a directory - not a command or executable.

My advise is to NOT overload the intended meaning of files. Learn to create a makefile like:
Quote:
[stevea@hypoxylon tmp]$ cat Makefile
LDLIBS="-lm"

p: p.c
Then the command 'make' does the right thing.
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
Reply With Quote
Reply

Tags
c compile bash script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fedora 12 running hot/fans running all the time Desh Banks Hardware & Laptops 12 12th April 2010 12:07 PM
Compiling and running an entire poject from command line/terminal on Linux tech291083 Programming & Packaging 11 19th February 2009 04:06 PM
Problems compiling Java in a terminal tech291083 Using Fedora 37 2nd June 2007 07:43 AM
Compiling Java in a terminal tech291083 Using Fedora 7 28th May 2007 02:59 PM
FC4 newbie qustions about compiling and terminal commands SneakyNINj4 Using Fedora 11 11th September 2005 10:52 PM


Current GMT-time: 19:49 (Tuesday, 21-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat