Laboratory Lecture 3
Laboratory Lecture 3
(CPET 410L)
escapes
echo -E argument ... do not interpret \
char escapes
Special echo Characters
Backslash character sequences have special
meaning
\a Alarm - ring the terminal bell
\b Backspace
\c Print without trailing newline (same as print
-n)
\f Form feed
\n Newline
\r Return
\t Tab
\v Vertical tab
\\ Backslash
\xxx Character with octal code xxx (up to
echo Examples
Example:
$ echo -e "Line 1\n\tLine2"
Output:
Line 1
Line2
The read Command
To get input while a Shell Script is
running, use read:
The read command allows you to prompt
#!/bin/bash
<commands>
<system/user defined variable>
<statements>
<control flow>
#!Program1: Save as
userinfo.sh
clear
echo “Hello “, $USER
echo “Welcome to Linux Shell Script”
echo “Today is”; date
sleep 5
clear
Sample Program
Where:
clear
echo “My Personal Information”
echo “Enter your first name”
read fname
echo “Enter your middle name”
read mname
echo “Enter your lastname”
read lname
echo “Welcome $lname $fname $mname”
echo “Today is”
date
sleep 5
The Bash Shell let Command
let argument ...
-or-
(( argument ))
interactively
reads arithmetic expression strings
expressions
set the scale variable inside bc to
Sample output:
Enter length:
Enter width:
The area of rectangle is:
Activity#2