+ 3

How do I write new Linux commands that support options?

How do I write new programs which shall run on Linux command line the same ways as the existing commands do, and which also can be used with the switches/options as ls-l,etc do?

22nd Jul 2018, 5:32 PM
Hardik Khane
Hardik Khane - avatar
7 odpowiedzi
+ 12
Linux has a very rich command line language, and commands can be put in a file and executed, like a .bat file in Windows. To start, you create a plain text file and put your commands in it. You then make your file executable. For instance, if your file name is "my_file", execute this command to make it executable: chmod 755 my_file To run it, execute this command: ./my_file If you are just getting started with Linux commands, enter "linux command line introduction" in your favorite search engine.
27th Jul 2018, 9:18 PM
Charlie Mitchell
Charlie Mitchell - avatar
+ 11
N00B, you should be able to put the script together the same way, and then just run it through the GUI just like any other executable (double click). Hope this helps. 🤙
28th Jul 2018, 2:30 AM
Charlie Mitchell
Charlie Mitchell - avatar
+ 9
I see what you're sayin' Hardik Khane. But I think N00B is lookin' for a simpler, more hands on, 'tactile' approach. Blueprints v construction...to make an analogy. Please correct me if I'm wrong.
28th Jul 2018, 7:49 AM
Charlie Mitchell
Charlie Mitchell - avatar
+ 3
Charlie Mitchell But I want to run the script without putting "./" in front of my script.
28th Jul 2018, 12:00 AM
N00B
+ 1
Charlie Mitchell I'll try tomorrow, thank you.
28th Jul 2018, 2:32 AM
N00B
+ 1
Adding the directory in which the executable is saved, to the PATH variable enables us to enter the command without ./ . But the problem of implementing the switches/options still remains.
28th Jul 2018, 3:53 AM
Hardik Khane
Hardik Khane - avatar
+ 1
Charlie Mitchell, I agree😀
28th Jul 2018, 8:09 PM
Hardik Khane
Hardik Khane - avatar