How to write new custom 'binaries'?
by SomeLinuxUser from LinuxQuestions.org on (#51G4N)
Newbie here, please forgive any abuse of terminology.
Suppose I want to write an open command-line utility, similar to what's available on MacOS, which will open a target file using the pre-specified program (zathura for pdfs, vim for .cpp files etc), preferably via a lookup from a .openrc config or similar. I wrote a post on here a while back looking for program which does this, and the users suggested writing one myself if I wanted it. Thought it was a good test case for how this stuff works.
I understand that files can be made executable with a chmod +x, so presumably one can just write a shell script which does something like this.
If you want a binary to be place in /usr/local/bin, would you write it in C, compile it and just put the output in there? I assume you don't place shell scripts in there?
Side question: How would you write such a binary which is capable of accepting an extra argument such as "open foo.pdf" -> run open with some variable saved as "foo.pdf"?


Suppose I want to write an open command-line utility, similar to what's available on MacOS, which will open a target file using the pre-specified program (zathura for pdfs, vim for .cpp files etc), preferably via a lookup from a .openrc config or similar. I wrote a post on here a while back looking for program which does this, and the users suggested writing one myself if I wanted it. Thought it was a good test case for how this stuff works.
I understand that files can be made executable with a chmod +x, so presumably one can just write a shell script which does something like this.
If you want a binary to be place in /usr/local/bin, would you write it in C, compile it and just put the output in there? I assume you don't place shell scripts in there?
Side question: How would you write such a binary which is capable of accepting an extra argument such as "open foo.pdf" -> run open with some variable saved as "foo.pdf"?