, , , ,

Difference between revisions of "Bash scripting"

From Camilo's web
Jump to: navigation, search
Mountain View
(Basic scripts)
 
m
Line 1: Line 1:
__TOC__
== How to create the script file ==
== 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
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

Revision as of 14:16, 20 April 2017

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.