https://github.com/niinpatel/basic-shell-scripting
If statements, While loops, Switch Case, Random Numbers and More using shell scripting.
https://github.com/niinpatel/basic-shell-scripting
bash scripting shell unix
Last synced: 4 months ago
JSON representation
If statements, While loops, Switch Case, Random Numbers and More using shell scripting.
- Host: GitHub
- URL: https://github.com/niinpatel/basic-shell-scripting
- Owner: niinpatel
- Created: 2018-06-07T16:22:26.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-11-01T17:48:23.000Z (over 5 years ago)
- Last Synced: 2024-10-24T02:31:35.323Z (over 1 year ago)
- Topics: bash, scripting, shell, unix
- Language: Shell
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# basic-shell-scripting
> /* About [SL Package](https://github.com/mtoyoda/sl)
> This package creates a steam locomotive animation on the terminal whenever you enter commands like sl or LS or any other misspelling or ls command.
(Works only for Linux).
*/
This program runs different steam locomotives continuously on your terminal.

__Use of :__
* [if then statements](https://www.tutorialspoint.com/unix/if-elif-statement.htm)
* [dpkg commands](https://linuxconfig.org/how-to-test-for-installed-package-using-shell-script-on-ubuntu-and-debian)
* [while loop](https://www.tutorialspoint.com/unix/while-loop.htm)
* [switch esac](https://www.tutorialspoint.com/unix/case-esac-statement.htm)
* [variable declaration](https://www.tutorialspoint.com/unix/unix-using-variables.htm)
* [random numbers generation.](https://blog.eduonix.com/shell-scripting/generating-random-numbers-in-linux-shell-scripting/)
__What it does.__
This is the basic shell scripting program which contains basic programming commands like *if statements*, *while loop*, *switch case* and more.
Here's the brief explanation of what is happening.
to run this script correctly, user needs to have [sl](https://github.com/mtoyoda/sl) installed in his computer, so the first thing this program does is to check if *sl* is installed or not.
we do this using an *if* then statement and a *dkpg* query. If the package is not there, it will install the package in automatically.
Next, if creates a *while loop* which runs forever. this can be achieved using while true; command.
inside the while loop, i will declare and initialize a variable called *train_number* and assign it a random number between 1 and 3.
Then I will use a *switch* statement. We will call a random train based on the number that is in the *train_number* variable.
finally we close the switch statement and while loop with *esac* and *done* respectively.
To run the script, clone into the repo and then type the following command on the terminal:
./simplebash.sh
This should start the script. To end it, you can just close the terminal.