Naming shell scripts

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

Naming shell scripts

myprogram
15
33%
myprogram.sh
19
41%
my-program.sh
4
9%
myProgram.sh
1
2%
my_program.sh
7
15%
MyProgram.sh (Really?)
0
No votes
MY_PROGRAM.sh (I guess you hate your users.)
0
No votes
 
Total votes: 46

srikanthsrs
Posts: 4
Joined: Sat Jun 07, 2008 7:49 am UTC
Location: India

Naming shell scripts

Postby srikanthsrs » Fri Jul 25, 2008 11:26 am UTC

I prefer the following two:

myprogram

or

my-program.sh

What's your opinion on camel cased executables?

And what about for Python or Perl scripts? Do you prefer appending the extension? What about binaries? I'm curious about binaries too because they seldom have extensions on *nix. For binaries I prefer nothing else but "mybinary"-like names. For example: dos2unix. Imagine typing dosToUnix, looks so ugly to me. What's your style doc?

Tarrantula
Posts: 20
Joined: Thu May 01, 2008 7:36 pm UTC

Re: Naming shell scripts

Postby Tarrantula » Fri Jul 25, 2008 4:36 pm UTC

I traditionally on short script names use camel case myProgram.sh. On longer names 'convert-mp3-ogg.sh' I use '-'.

As for perl and python scripts if the program is meant to run as a program then no suffix, if its a script or library add the suffix.

Rysto
Posts: 1460
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Naming shell scripts

Postby Rysto » Fri Jul 25, 2008 9:07 pm UTC

Code: Select all

$ ls ~/scripts/
config_build            idrvr_copy              stopview
copyKernel              kernel64                summarizePerfTest
copyKernelFuncs         link_hierarchy          updatePackages
doDiff                  process_profile         update_src_tree
get64                   run_pmcstat             use_home_keys.sh
init_idrvr              startview               watch_tpc

I'm a bit inconsistent on this...

User avatar
Korandder
Posts: 161
Joined: Fri Sep 14, 2007 6:12 am UTC
Location: LoadingReadyRun Australian Astrophysical Observatory
Contact:

Re: Naming shell scripts

Postby Korandder » Sat Jul 26, 2008 6:57 am UTC

My shell scripts tend to be all lower case with no extension but I rarely write them. My Python and Perl files always have the appropriate suffix and are in camel case. My Python modules tend to start with uppercase as if they were Java source files.
Image

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Naming shell scripts

Postby Berengal » Sun Jul 27, 2008 6:43 am UTC

I'm from the school that if a single word isn't good enough, I'll abbreviate. Incomprehensibly if needed. Everything gets extensions, mostly .py for python and .sh for bash.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
mat-tina
Posts: 331
Joined: Mon Jun 02, 2008 3:33 pm UTC

Re: Naming shell scripts

Postby mat-tina » Mon Jul 28, 2008 4:46 pm UTC

my_program.sh for programs that are related to grouping commands that I usually use from the CLI, and just don't bother to type over and over again, my-program for scripts that act like real programs.

As for Python files, I use myprogram or my-program for the main file (the one to be installed in bin-directories) and myprogram.py for the source.

Daemons are always mydaemond, though I have only written one of those.
Felltir wrote:has no sig, and therefore something to hide
GENERATION n: The first time you see this, copy it into your sig on any forum. If n is an even number, divide it by 2. If it's odd, multiply it by 3 and add 1. Prove that this sequence converges to 1 for all n.

fencerjimmy
Posts: 6
Joined: Mon Jul 28, 2008 5:52 am UTC

Re: Naming shell scripts

Postby fencerjimmy » Wed Aug 06, 2008 3:27 am UTC

Shell scripts and perl/python files I plan to run from the command line are myprogram or my_program. Scripts I write mainly to be called from other scripts have the appropriate extension, as do all data/document files. (I write lots of small single-purpose data-processing scripts which I pass data to in other scripts.) That way, when I ls, I always know the items without extensions are the human-runnable programs.

User avatar
phlip
Restorer of Worlds
Posts: 7572
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Naming shell scripts

Postby phlip » Wed Aug 06, 2008 3:36 am UTC

Any scripts I write that live in $PATH (mostly in ~/bin) have no extension... regardless of whether they're written in in bash, perl, python, whitespace...

Scripts that live in some random directory generally have .sh/pl/py attached.

I don't know how I got into this habit, but that's what I do.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
Dingbats
Posts: 921
Joined: Tue Mar 20, 2007 12:46 pm UTC
Location: Sweden
Contact:

Re: Naming shell scripts

Postby Dingbats » Sun Aug 10, 2008 8:09 pm UTC

phlip wrote:Any scripts I write that live in $PATH (mostly in ~/bin) have no extension... regardless of whether they're written in in bash, perl, python, whitespace...

Scripts that live in some random directory generally have .sh/pl/py attached.

I don't know how I got into this habit, but that's what I do.

Same here. Although I'm a bit hesitant whether to use .sh or not for shell scripts. Regarding the names, I'm like Berengal that I don't want them to be long-winded. Maybe like eight characters tops, all lowercase.

btilly
Posts: 1877
Joined: Tue Nov 06, 2007 7:08 pm UTC

Re: Naming shell scripts

Postby btilly » Sun Aug 10, 2008 10:30 pm UTC

I voted myprogram and my-program.sh because the real answer is my-program and it wasn't available.
Some of us exist to find out what can and can't be done.

Others exist to hold the beer.

User avatar
abrenecki
Posts: 62
Joined: Mon Sep 10, 2007 8:39 am UTC
Location: Mid North SA, Australia

Re: Naming shell scripts

Postby abrenecki » Sun Aug 24, 2008 11:07 am UTC

Code: Select all

SCIENCE-4:~ ab$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Volumes/Files/PATH
SCIENCE-4:~ ab$ ls /Volumes/Files/PATH
calcw      getxkcd      gfrun      pcalc      vector
foo      getxkcd-old   mental      untitled folder   xkcd
SCIENCE-4:~ ab$ head -n 1 /Volumes/Files/PATH/getxkcd
#!/usr/bin/python
SCIENCE-4:~ ab$

Everything not on my PATH has an extension. gfrun is a shellscript that cd's to a Django app and starts the development server. calcw goes through /usr/share/dict/words and picks out words you can spell upside-down on a calculator.


Return to “Religious Wars”

Who is online

Users browsing this forum: No registered users and 4 guests