After using linux for a month or two, I know what I'm doing now.

When creating programs, using whatever language, I've obviously been using code like this:

$ python test.py

And so if I wanted test.py to read a given file, I would have to use:

$ python test.py something.file

What I'd like to do now, it try and create a command line application, so I can use

$ myapp something.file

A program like the python in $ python test.py, or the nano in $ nano program.pl

But where on earth do I start building applications like these? A bit of web trawling has got me nowhere.

If you can tell me yourself that would be great, but I'll readily accept a bunch of links.

I'm totally open if there's more than one way, I don't really mind what language (an excuse to learn another!) or whatever.

closed as too broad by Michael Homer, Scott, cuonglm, jimmij, Sparhawk Jan 19 '16 at 5:03

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    Do you want to learn Unix C programming or do you just want to be able to run your python scripts without having to specify the python part? – jw013 Jul 14 '12 at 18:19
  • @jw013 I want to learn Unix C programming. (Though I would be interested to know how you could run python scripts without the python.) – ACarter Jul 14 '12 at 18:25
  • 4
    You should probably fix your question then :) CLI applications can be written in any language that has a Unix compiler or interpreter, so if you are only interested in C, say so. Unix C programming is actually two parts - the Unix part and the C part. As it is, "How do I learn Unix C programming?" will probably get closed for being too general, and there's probably duplicates all over this site. "How do I learn C programming" is also too general and possibly off-topic as well. It'd certainly get closed on SO. – jw013 Jul 14 '12 at 18:28
  • @jw013 What I'm really after is advice like "CLI applications can be written in any language that has a Unix compiler or interpreter", so thanks. – ACarter Jul 14 '12 at 18:59
  • 1
    Ah, ok. There's always a bit of a steep initial hump in the learning curve when trying to get into the Unix environment, but once you get past it I'm sure you'll find the effort was worth it. Unfortunately, I don't know of any one resource that I can point to for getting started - you basically have to pick up bits and pieces as you go :\ Best of luck to you on your journey :) – jw013 Jul 14 '12 at 19:08

You can run python scripts by making them executable (chmod +x test.py) and making #!/usr/bin/env python the first line. Once you do that, running test.py args will invoke python to run your script. Read about shebang's if you want to learn more.

  • That didn't work for me. $ test.py 30 gave a bash error: -bash: test.py: command not found. Thanks for your help so far though! – ACarter Jul 14 '12 at 18:31
  • 8
    @ACarter That's because it's not in your $PATH. Either use a path, like /path/to/test.py or ./test.py if you are in /path/to already, or add /path/to to your $PATH. There are many duplicate questions on this site about the latter. – jw013 Jul 14 '12 at 18:32
  • As soon as you put something in your $PATH, leave out file endings like .py. – Reactormonk Jul 15 '12 at 11:23
  • You need the #!/usr/bin/env python at the top of your script before you can remove the .py extension. But any script which contains this invocation or some similar one (e.g. #!/bin/sh for shell scripts) can be named without an extension. It has nothing to do with whether it's in your PATH or not. – Michael Hampton Jul 15 '12 at 15:32
  • 2
    Just to be clear, extensions don't matter in the Unix world, unlike in Windows. where extensions like .EXE and .COM matter. However, the rationale behind removing the extension is that generic executables should just be generic executables. The meaning of this tautology is the users just want the functionality and should not need to know or care whether it is Perl or Python or sh or bash or awk etc. - that's a mostly irrelevant implementation detail. And, making a script executable and adding a shebang makes it a generic executable. – jw013 Jul 15 '12 at 18:13

In C, it looks like this:

int main(int argc, char *argv[]) {

The argc is the number of arguments. Note that the program/tool name counts.

The arguments themselves end up in the argument vector (or array), argv.

Then there is the tricky part of writing code to deal with them the intended way.

Then compile with gcc. You specify the name of the program with the -o (outfile) flag. Run the file from its current directory like this: ./tool_name input_file_1 ... input_file_n (or put it in a directory that turns up when you write echo $PATH, then you can invoke it from anywhere, i.e., without the dot).


I use Go. It's a compiled language, cross-platform, with the ease of programming of a dynamic language, and support for concurrency and communication.

I'm not going back to Python since it's very funny to develop with Go.


Here you have a simple program which gets the arguments used in that command:

package main

import (

func main() {
  fmt.Println("Arguments: ", flag.Args())


  • Go is great for some targeted use-cases; however, comparing Go and Python for general utilities is like comparing a hunting knife (Go) with a swiss army knife (Python) – Mike Pennington Jul 15 '12 at 17:56
  • 1
    Go is a general-purpose language, which is being used i.e in Youtube, in web applications, or to build games (there is a game finished and another ones in developing). In addition of to be used in CLI applications. – Marc Jul 15 '12 at 20:33
  • 5
    He just wants to know how to make an executable program; we don't really need to get in a language war – Michael Mrozek Jul 15 '12 at 22:22

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