Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a 'shebang' line?

Currently I'm trying to start programming on my new Mac. I installed TextWrangler, and chose C++ as my language of choice; since I have some prior knowledge of it, from when I used Windows.

So, I wrote the ever so common "Hello World" program. Although, when I tried to run it, I got an error:

"This file doesn’t appear to contain a valid ‘shebang’ line (application error code: 13304)"

I tried searching the error code to find out how to fix this, but I couldn't find anything.. I have no idea what a 'shebang' line is... Can someone help me out?

like image 815
James Litewski Avatar asked Jan 18 '23 23:01

James Litewski


1 Answers

You need to compile it with a compiler first. I assume you tried to run the source file like ./source but C++ doesn't work this way.

With some compilers however, you can provide a shebang-line as the first line of the source file (the #! is known as shebang or crunchbang, hence the name), like so:

#!/path/to/compiler

So that the shell knows what application is used to run that sort of file, and when you attempt to run the source file by itself, the compiler will compile and run it for you. That's a compiler-dependent feature though, so I recommend just plain compiling with G++ or whatever Macs use to get an executable, then run that.

like image 94
Seth Carnegie Avatar answered Jan 31 '23 16:01

Seth Carnegie