Skip to main content
Engineering LibreTexts

13-C.9: Script Permissions / Script Extensions

  • Page ID
    43207
  • 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.

    • Was this article helpful?