, , , ,

Bash scripting

From Camilo's web
Revision as of 14:16, 20 April 2017 by Camilo (talk | contribs)
Jump to: navigation, search
Mountain View

How to create the script file

To create a bash script accessible globally throughout the terminal, you need to put it in a root folder accessible to the whole system. A good place to put it is

/usr/local/bin

There you can create (using your root role) the script file my_script, which should look like this:

#!/bin/bash
script line 1
script line 2
...

and once the coding is done, you need to make it executable

sudo chmod +x my_script

Examples

Alias to open a pdf file with TexShop

The script is called ts and it contains the following lines:

#!/bin/bash
open -a TexShop "$1"

Here the ''$1'' means that the script requires a parameter, which is this case is the file that you want to open.