0% found this document useful (0 votes)
2 views16 pages

Beginner's Guide to Shell Scripting

This document provides an introduction to shell scripting using Bash in Fedora, detailing what a shell and shell script are. It covers the creation, execution, and common commands of shell scripts, along with control structures, debugging techniques, and best practices. Additionally, it includes practice exercises and resources for further learning.

Uploaded by

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

Beginner's Guide to Shell Scripting

This document provides an introduction to shell scripting using Bash in Fedora, detailing what a shell and shell script are. It covers the creation, execution, and common commands of shell scripts, along with control structures, debugging techniques, and best practices. Additionally, it includes practice exercises and resources for further learning.

Uploaded by

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

Introduction to Shell Scripting

• Using Bash in Fedora


Instructor: [Your Name]
What is a Shell & Shell Script?

• Shell: Command-line interpreter between user and OS kernel.


Shell Script: File containing commands executed by shell.
Common extension: .sh
Popular Shells

• Bash (Bourne Again Shell) – Default in Fedora


Other shells: sh, ksh, zsh, csh
Why Use Shell Scripts?

• • Automate repetitive tasks


• Easy system administration
• Quick execution without compilation
Creating Your First Script

• #!/bin/bash
echo "Hello, Fedora!"

Save as [Link]
chmod +x [Link]
./[Link]
Running Scripts in Fedora

• Run: bash [Link] or ./[Link]


Ensure permissions: chmod +x [Link]
Common Shell Commands

• ls – list files
cd – change directory
pwd – print working directory
cp, mv – copy/move files
chmod – change permissions
echo – display text
Variables & Special Parameters

• Assign variable: NAME="Alice"


Access: echo "Hello $NAME"

Special variables:
$0 – script name
$1..$9 – arguments
$# – number of arguments
$? – exit status
Taking Input

• read NAME
echo "Hello $NAME"
Control Structures

• if-else:
if [ $1 -gt 10 ]; then
echo "Greater than 10"
else
echo "Less or equal to 10"
fi

Loop:
for i in 1 2 3; do
echo $i
done
Sample Script

• #!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: $0 name..."
exit 1
fi
for name in "$@"; do
echo "Hello, $name!"
done
Debugging & Best Practices

• • Use bash -x [Link] for debugging


• Use comments (#) to explain code
• Check exit status with $?
Redirection & Pipes

• Redirect output: command > file


Append: command >> file
Pipe: command1 | command2
Fedora Tips

• • Open Terminal: Ctrl+Alt+T


• Editors: nano, vim, gedit
• Use sudo for root permissions
Practice Exercises

• 1. Script to count files in current directory


2. Script to display current date & time
3. Script to read a name and greet user
4. Backup script using tar
Resources

• • [Link]
• [Link]
• [Link]

You might also like