Difference between revisions of "Desktop scripting/sh"
Jump to navigation
Jump to search
(8 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
With an SH script, almost anything you can in the terminal can be written in advance, and played back at your leisure. | With an SH script, almost anything you can in the terminal can be written in advance, and played back at your leisure. | ||
− | |||
− | |||
===Setting up an SH script=== | ===Setting up an SH script=== | ||
Line 13: | Line 11: | ||
::* this will create a blank plain text file of that name | ::* this will create a blank plain text file of that name | ||
: 3) Open the file you've just created | : 3) Open the file you've just created | ||
− | : | + | :* Use whatever you like to open it. VIM, nano, gedit, Atom, vsCode, etc are all fine |
+ | : 4) Write your script. | ||
+ | :: 1) set the language that you'll be scripting in | ||
+ | ::* Your can use any language available to your terminal | ||
+ | ::* I always use bash, so my example is for bash: | ||
+ | :::* on the first line of your file, paste: | ||
+ | :::: <code>#!/bin/bash</code> | ||
+ | :: 2) start scripting | ||
+ | ::* Your script begins on the second line, after your language declaration. | ||
+ | :::* seperate commands with " && " | ||
+ | ::* this is just a silly example, so It's just a hello world | ||
+ | ::: <code>echo "hello world"</code> | ||
+ | |||
===Using an SH script=== | ===Using an SH script=== | ||
+ | |||
+ | : 1) cd to the folder where you have your script | ||
+ | : 2) Run: | ||
+ | ::: <code>sh [nameOfYourFileHere].sh</code> | ||
+ | |||
+ | ===Advanced usage=== | ||
+ | |||
+ | sh scripts can of course do far more than this, and I may one day cover it. | ||
+ | |||
+ | For example, they can provide input to terminal commands that require USER input! | ||
+ | |||
+ | But for now, I leave you to https://www.google.com/ |
Latest revision as of 16:53, 2 September 2020
SH scripting!
(available on POSIX systems)
With an SH script, almost anything you can in the terminal can be written in advance, and played back at your leisure.
Setting up an SH script
- 1) cd to the folder where you'd like to save your script
- 2) run:
- touch [nameYourFileHere].sh
- this will create a blank plain text file of that name
- touch [nameYourFileHere].sh
- 3) Open the file you've just created
- Use whatever you like to open it. VIM, nano, gedit, Atom, vsCode, etc are all fine
- 4) Write your script.
- 1) set the language that you'll be scripting in
- Your can use any language available to your terminal
- I always use bash, so my example is for bash:
- on the first line of your file, paste:
#!/bin/bash
- 2) start scripting
- Your script begins on the second line, after your language declaration.
- seperate commands with " && "
- this is just a silly example, so It's just a hello world
echo "hello world"
- 1) set the language that you'll be scripting in
Using an SH script
- 1) cd to the folder where you have your script
- 2) Run:
sh [nameOfYourFileHere].sh
Advanced usage
sh scripts can of course do far more than this, and I may one day cover it.
For example, they can provide input to terminal commands that require USER input!
But for now, I leave you to https://www.google.com/