Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am using Ubuntu 12.04 LTS and I am stuck at creating a simple .bin file which can print a message "hi" or anything else. My objective is to create a binary file.I have searched but didn't found anything helpful to me. So may I know how can I create a .bin file.

share|improve this question
2  
the extension .bin usually indicates a binary file - more than likely compiled - so if you intend to have a binary file you should pick a programming language, write a program, test it then compile it to get an executable file. –  pfeiffep Mar 16 '13 at 21:04

2 Answers 2

up vote 2 down vote accepted

Extensions are irrelevant, you can name a file dead.letter and it can still print "hi".

The following terminal commands will create a file named hello.bin, make it executable and print "hello" when executed:

cat > hello.bin <<EOF
#!/bin/sh
echo Hello World
EOF
chmod +x hello.bin

Executing ./hello.bin gives:

Hello World

This is a shell script, interpreted by the /bin/sh program (which is actually the /bin/dash program on Ubuntu).

The following writes source code to hello.c, the following command creates a binary program from this code:

cat > hello.c <<EOF
#include <stdio.h>
int main(void) {
    puts("Hello World");
    return 0;
}
EOF
gcc hello.c -o hello.bin

Executing ./hello.bin gives you Hello World too.

share|improve this answer
    
Thank you for the answer. I will let you know after trying it. –  AgentCool Mar 17 '13 at 4:13

I am new to ubuntu community but had this as a bookmark on my browser. You can see if this helps.

http://www.ehow.com/how_5962897_create-bin-file-ubuntu.html

share|improve this answer
    
Thanks for the information. –  AgentCool Mar 17 '13 at 4:11
2  
@prohank When you have a link to a page that you believe answers teh question, it's considered best to include the essential parts of the answer here, and provide the link for reference. If you wish to do that, you can edit your post to add your summary of the information. –  Eliah Kagan Jan 11 at 11:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.