13-C.9: Script Permissions / Script Extensions

Linux - The Penguin Marches On · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    Read aloud

    How

    Speed: 1×
    Light up
    Highlight

    Symbols: Mulberry Symbols, © 2018–2026 Steve Lee, CC BY-SA 4.0 (licence, the set), the site's own copies.

    From LibreTexts, under CC BY-NC 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    13-C.9: Script Permissions / Script Extensions

    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.