0% found this document useful (0 votes)
7 views3 pages

Shell Scripting Basics and Examples

Shell scripting involves writing a series of Linux/Unix commands in a text file to automate tasks. Key features include support for variables, loops, conditionals, and the ability to execute system commands. Popular interpreters include bash and zsh, and scripts can be executed with proper permissions and debugging options.

Uploaded by

rsramaneekaanth
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Shell Scripting Basics and Examples

Shell scripting involves writing a series of Linux/Unix commands in a text file to automate tasks. Key features include support for variables, loops, conditionals, and the ability to execute system commands. Popular interpreters include bash and zsh, and scripts can be executed with proper permissions and debugging options.

Uploaded by

rsramaneekaanth
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Shell Scripting - Detailed Notes

Creditation: Raksha

Group: Bughunters

Section: A

What is Shell Scripting?

Shell scripting is the practice of writing a sequence of Linux/Unix shell commands in a plain text file,

known as a script, which can be executed as a program.

Key Features:

- Automates manual command-line tasks

- Supports Variables, Loops, Conditionals, Functions

- Executes system-level commands

- Ideal for file ops, cron jobs, and automation

Popular Shell Interpreters:

- sh: Original Bourne shell

- bash: Bourne Again Shell (most used)

- zsh: Feature-rich, customizable shell

- ksh: Korn Shell

- csh: C-style Shell

Basic Structure of a Shell Script:

#!/bin/bash

# This is a comment

echo "Hello, world!"


1. Variables:

name="Raksha"

echo "Hello, $name"

2. User Input:

read user

echo "Welcome, $user"

3. Conditionals:

if [ "$user" == "Raksha" ]; then

echo "Welcome, Raksha!"

else

echo "Access Denied"

fi

4. Loops:

for i in 1 2 3 4

do

echo "Number: $i"

done

5. Functions:

greet() {

echo "Hello $1"

greet "Alice"
Script Execution:

chmod +x [Link]

./[Link]

Tips:

- Quote variables: "$var"

- Use set -e to exit on error

- Use #!/bin/bash -x for debugging

Example: Backup Script

#!/bin/bash

echo "Backing up files..."

tar -czvf [Link] /home/username/Documents

echo "Backup complete."

You might also like