Skip to main content
Engineering LibreTexts

13-C.9: Script Permissions / Script Extensions

  • Page ID
    43207
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Script Permissions

    A shell script can be executed using the following syntax:

    pbmac@pbmac-server $ chmod +x script.sh
    pbmac@pbmac-server $ ./script.sh
    
    Normally the cwd, that is the current directory, is not in the PATH. If it is, then you do not need the ./ before
    the script name.
    

    The script can also be run directly without setting the script execute permission by running a new instance of bash, or by using the dot format, which is the same as using the source command.

    bash script.sh
    . script.sh
    

    Script Extensions

    An often asked question is what is the appropriate extension for a shell script. In reality, the extension has no bearing, in Linux, on how the script gets executed. It is the shebang line that determines what shell is used for the execution of the script. There are some exceptions, noted above, in the discussion of permissions, where a script can be executed in the current shell environment.

    The convention is that shell scripts have the .sh extension. However, this is only a visual help to someone looking through a list of files, knowing that all of the .sh files are shell scripts. An organization can create their own standards, without fear of going against any standard.


    13-C.9: Script Permissions / Script Extensions is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?