0% found this document useful (0 votes)
33 views2 pages

12.5 Basic Shell Scripts

The document provides examples of basic shell scripts for performing common tasks like outputting text, defining variables, reading user input, running commands, and renaming files. The scripts demonstrate how to write simple shell scripts using commands like echo, read, whoami, date, mv and defining/accessing variables to output text, read input, run system commands, and perform a renaming task.

Uploaded by

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

12.5 Basic Shell Scripts

The document provides examples of basic shell scripts for performing common tasks like outputting text, defining variables, reading user input, running commands, and renaming files. The scripts demonstrate how to write simple shell scripts using commands like echo, read, whoami, date, mv and defining/accessing variables to output text, read input, run system commands, and perform a renaming task.

Uploaded by

Ashish Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Basic Shell Scripts:

Output to screen

#!/bin/bash
# Simple output script

echo "Hello World"

Defining Tasks

#!/bin/bash
# Define small tasks

whoami
echo
pwd
echo
hostname
echo
ls -ltr
echo

Defining variables

#!/bin/bash
# Example of defining variables

a=Imran
b=Afzal
c=’Linux class’

echo "My first name is $a"


echo "My surname is $b"
echo ‘My surname is $c’

Read Input

#!/bin/bash
# Read user input

echo "What is your first name?"


read a
echo

echo "What is your last name?"


read b
echo

echo Hello $a $b

Scripts to run commands within

#!/bin/bash
# Script to run commands within

clear
echo "Hello `whoami`"
echo
echo "Today is `date`"
echo
echo "Number of user login: `who | wc -l `"
echo

Read input and perform a task

#!/bin/bash
# This script will rename a file

echo Enter the file name to be renamed


read oldfilename

echo Enter the new file name


read newfilename

mv $oldfilename $newfilename
echo The file has been renamed as $newfilename

You might also like