Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 29348  / 2 Years ago, mon, april 18, 2022, 8:04:54

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.


More From » packaging

 Answers
5

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.


[#32179] Tuesday, April 19, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nalystcul

Total Points: 390
Total Questions: 106
Total Answers: 115

Location: Tokelau
Member since Sun, May 7, 2023
1 Year ago
;