KwickAcademy Course Topics · 6 min · free
Writing and executing simple shell scripts
Write and run simple shell scripts: write, save .sh, chmod +x, ./ run, common errors, variables, read, arithmetic and an if for pass or fail. Save commands in a .sh file, give permission with chmod +x, then run it with ./file.sh.
Follows the syllabus of: GSEB Std 11 Computer Studies
On screen in this lesson
Shell and shell script
| Shell: a program that reads and runs your commands |
| Bash is the common shell in Ubuntu Linux |
| Shell script: a text file full of commands |
| The shell runs the commands one by one, top to bottom |
Steps to make a script
| Step | What you do | Example |
|---|---|---|
| 1. Write | open an editor | gedit hello.sh |
| 2. Save | use .sh ending | hello.sh |
| 3. Permit | allow running | chmod +x hello.sh |
| 4. Run | execute it | ./hello.sh |
Two ways to run it
| Command | Needs chmod? | Meaning |
|---|---|---|
| bash hello.sh | No | bash reads file |
| chmod +x hello.sh | - | adds execute right |
| ./hello.sh | Yes | run from here |
The common error
| ./hello.sh without chmod gives: Permission denied |
| Fix: chmod +x hello.sh, then run again |
| hello.sh alone gives: command not found |
| Fix: type ./ before the file name |
Comparing numbers
| Test | Means | Example |
|---|---|---|
| -eq | equal to | [ $a -eq 5 ] |
| -ne | not equal to | [ $a -ne 5 ] |
| -gt and -lt | greater, less | [ $a -gt 5 ] |
| -ge and -le | or equal to | [ $a -ge 5 ] |
Quick recap
| A shell script is a text file of commands, saved as .sh |
| Start with #!/bin/bash; # lines are comments |
| Run with bash file.sh, or chmod +x then ./file.sh |
| No spaces around = ; use $ to read a variable |
| read takes input; $(( )) does arithmetic; if ends with fi |
Quick answers
hello.sh alone gives command not found. Fix?
Type ./ before the file name.
a=45, b=30, sum=$((a + b)). What is sum?
75.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
The full lesson, in text
Hello students, welcome to Kwickprep. Do you type the same Linux commands again and again? You can save them in one file and run them with a single command. Today we will write, save and run simple shell scripts, and fix the most common error.
First, two new terms. The shell is a program that reads the commands you type in the terminal and runs them. Bash is the shell most Linux systems, like Ubuntu, use. A shell script is simply a text file that stores many commands. When you run the script, the shell runs those commands one by one, from top to bottom.
Every script is made in four steps. First, open a text editor like gedit or nano, and type your commands. Second, save the file with a name ending in the .sh ending, like hello.sh. Third, give the file execute permission with the chmod command. Fourth, run the script from the terminal.
Here is our first script. The first line is called the shebang. It tells Linux to use the bash shell to run this file. A line starting with a hash sign is a comment, and the shell ignores it. The echo command prints text on the screen. So this script prints two lines.
There are two common ways to run a script. You can type bash, space, hello.sh, and bash reads the file directly. Or you first type chmod +x, which adds execute permission to the file. Then you type dot slash hello.sh. Dot slash means the file is in the current folder.
Two errors trouble almost every beginner. If you run dot slash hello.sh before chmod, Linux says Permission denied. The fix is chmod +x, and then run it again. If you type only hello.sh, without dot slash, the shell says command not found. The fix is to add dot slash before the name.
A variable is a named box that stores a value. Here, name stores Riya and marks stores seventy two. There must be no space around the equals sign. To use the value, put a dollar sign before the name. So the script prints, Riya scored seventy two.
A script can also ask the user for input. The read command waits for the user to type something and press Enter. Whatever is typed is stored in the variable name. If the user types Aman, the script prints, Welcome, Aman.
The shell treats values as text, so for arithmetic we use double brackets. Dollar, double open bracket, a plus b, double close bracket, calculates the sum. Forty five plus thirty is seventy five. Older books use the expr command for the same job, like expr a plus b, with spaces around the plus.
To make decisions, the shell compares numbers with special words inside square brackets. Hyphen e q means equal to. Hyphen n e means not equal to. Hyphen g t means greater than, and hyphen l t means less than. Hyphen g e and hyphen l e also say yes when the numbers are equal. Always keep a space after the opening bracket and before the closing bracket.
Here is a pass or fail script. The if line tests whether marks is greater than or equal to thirty three. The semicolon lets us write then on the same line, and then starts the yes block. Else starts the no block. The word fi, which is if written backwards, closes the if. Pause and predict. Marks is exactly thirty three, so what prints? It prints Pass, because -ge includes thirty three.
Let us put it all together in the terminal. The dollar sign here is only the terminal prompt, so do not type it. First, gedit result.sh opens the editor, and we type the script and save. Next, chmod +x gives permission. Then dot slash result.sh runs it, and the screen shows Pass.
Let us revise what we learned today. A shell script is a text file of commands, saved with a .sh ending. It starts with the shebang line, and lines beginning with a hash are comments. Run it with bash, or give chmod +x and then use dot slash. Never put spaces around the equals sign, and use a dollar sign to read a variable. Read takes input, double brackets do arithmetic, and every if ends with fi.
Courses that teach this
| Course | Unit |
|---|---|
| GSEB Std 11 Computer Studies | Vim Editor and Basic Scripting |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.


