Quick Tutorial on How to Use Shell Scripting in Linux: Coin Toss App

Simply put a Shell Script is a program that is run by a UNIXLinux shell. It is a file that contains a series of commands which are executed sequentially as if they were entered on the command line interface CLI or terminal.

In this quick tutorial on Shell Scripting we will write a simple program to toss a coin. Basically the output of our program should be either HEADS or TAILS of course randomly.

To start with the first line of a shell script should indicate which interpretershell is to be used to execute the script. In this tutorial we will be using binbash and it will be denoted as binbash which is called a shebang.

Next we will be using an internal Bash function 8211 a shell variable named RANDOM. It returns a random actually pseudorandom integer in the range 0-32767. We will use this variable to get 2 random values either 0 for HEADS or 1 for TAILS. This will be done via a simple arithmetic operation in shell using Modulus operator returns remainder RANDOM2 and this will be stored in a result variable. So the second line of our program becomes ResultRANDOM2 Note that there should be no space around assignment operator while assigning value to a variable in shell scripts.

...

Read Full Post

News Link: https://www.linuxjournal.com/content/quick-tutorial-how-use-shell-scripting-linux.

Linux Chatter is a news aggregator service that curates some of the best Linux, Cloud, Technical Guides, Hardware and Security news. We display just enough content from the original post to spark your interest. If you like the topic, then click on the 'read full post' button to visit the author's website. Use Linux Chatter to find content from amazing authors!

Note: The content provided has been modified and is not displayed as intended by the author. Any trademarks, copyrights and rights remain with the source.

Disclaimer: Linux Chatter sources content from RSS feeds and personal content submissions. The views and opinions expressed in these articles are those of the authors and do not necessarily reflect those of Linux Chatter.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.