Shell – An official standard / convention for a file extension for shell scripts to source

conventionsshellshell-scriptstandard

I was wondering if there is a convention for file type extensions for shell scripts you want to source instead of run. For example:

  1. If I want to run this script in a subshell.

     ./script.sh 
    
  2. If I want to remember to run this script from the current shell.

     . script.source 
    

Is there a convention (like POSIX for example) for a filetype in the second example? Something like .source or .sourceme?


Update

This question does not ask about any opinion. I clearly stated that I would like to know if there is a standardized file extension for this kind of scripts. This question is even less opinion-based than this well received question on a similar issue (Use .sh or .bash extension for bash scripts?).

Best Answer

I'd use .sh (for files in the POSIX sh language, .bash for non-sh-compatible bash files, that is the extension identifies the language the script is written in) for files intended to be sourced (or more generally not intended to be executed), and no extension for files that are meant to be executed.

You can also add a:

#! /bin/echo Please-source

she-bang, so that when executed by mistake (though I'd expect those files should not be given execution permissions, which would already prevent execution), you get a notice that it should be sourced instead.

Related Question