Docsity

shell program examples, Assignments of Programming Languages

Toggle sidebar
bg1
Example 1
#!/bin/sh
echo "What is your name?"
read PERSON
echo "Hello, $PERSON"
output
$./test.sh
What is your name?
Zara Ali
Hello, Zara Ali
$
Example 2
$cat my_script.sh
clear echo "This is my first shell script."
echo "Today’s date is `date | cut –d " " –f 1–3`"
echo "Now the time is `date | cut –d " "–f 4`"
echo "GOOD LUCK" $
output
$sh my_script.sh
This is my first shell script.
Today's date is Tue Nov 26
Now the time is 13:05:57
GOOD LUCK $
pf3

Partial preview of the text

Download shell program examples and more Assignments Programming Languages in PDF only on Docsity!

#!/bin/sh

echo "What is your name?"

read PERSON

echo "Hello, $PERSON"

output

$./test.sh

What is your name?

Zara Ali

Hello, Zara Ali

Example 2

$cat my_script.sh clear echo "This is my first shell script." echo "Today’s date is date | cut –d " " –f 1–3" echo "Now the time is date | cut –d " "–f 4" echo "GOOD LUCK" $ output $sh my_script.sh This is my first shell script. Today's date is Tue Nov 26 Now the time is 13:05: GOOD LUCK $

$cat readname.sh echo what is your name ? read name echo The name is $name. output : $chmod u+× readname.sh $readname.sh what is your name? murthy Example 4 $cat example echo Input a value for x read x echo the value of x is $x readonly x x=expr $x + 1 echo The value of x now is $x output : $sh example Input a value for x The value of x is 4 example: line 5: x: readonly variable