Main Menu

search

You are here

Linux: Script Files

[last updated: 2022-12-12]
Linux home page
Linux script programming
-----

Disclaimer as usual: This is my current best guess as to what's going on...

  • Script files end with .sh extension
  • Create script files with any text editor
    You must make the text file executable.
  • The first line of the script file must be:
    #!/bin/bash
  • Script files contain linux commands
  • Script files can contain lines to execute eg. Python programs:
    -------------------------------------------

  • Create and execute a script file:
    • make a file named test02.sh,
      that contains three lines:
         #!/bin/bash
         pwd
         ls
    • make the file executable:
      $ sudo chmod +x test02.sh
      -or- in File Manager:
        right-click the file
        select Properties (at bottom of drop-down) > Permissions
        click "Allow executing file as program"
  • execute script files with:
    $ [path-to-directory-where-file-is-located]/test02.sh
    or, if you are currently in the directory where the file is located,
          -or- if you set the PATH to include the directory where your script files are located
    execute it with:
    $ ./test02.sh
    --------------------------------------------------------------------------------

  • Change directory using a script file, and make the new directory persist after the command is done:
    • Add exec bash to the end of your file:
        #!/bin/bash
        cd "/home/jay/Documents"
        exec bash

    ---------------------------------------------------------------------

  • see [...here...] for using script files to edit metadata on audio/music files ...

-------------------------------------------------

  • See also:
    run script file at startup on rPi
  • .

    .

    .

    eof