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

Exer 3

The document contains three shell scripts: simple.sh, guessing_game.sh, and text_conversion.sh. simple.sh demonstrates basic shell scripting with variable handling and user input, guessing_game.sh implements a number guessing game with input validation, and text_conversion.sh renames .txt files to .text format. Each script showcases different functionalities and techniques in shell scripting.

Uploaded by

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

Exer 3

The document contains three shell scripts: simple.sh, guessing_game.sh, and text_conversion.sh. simple.sh demonstrates basic shell scripting with variable handling and user input, guessing_game.sh implements a number guessing game with input validation, and text_conversion.sh renames .txt files to .text format. Each script showcases different functionalities and techniques in shell scripting.

Uploaded by

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

Patagnan, Xyryz Lab Exercise 1.

3 Operating Sytems
1. simple.sh

#!/bin/sh
# this is a comment
echo "The number of arguments is $#"
echo "The arguments are $*"
echo "The first is $1"
echo "My process number is $$"
echo "Enter a number from the keyboard: "
read number
echo "The number you entered was $number"

2. guessing_game.sh
#!/bin/sh

num=$(( 1+(`od -An -N2 -I /dev/urandom`)%(100-1+1) ))


echo “Guess the number from 1-100”

while true
do
echo “Enter guess: ”
read guess
if [ ! $guess =~ ^[0-9]* ] || [ $guess -lt 1 ] || [ $guess -gt 100 ]
then
echo “Please enter valid number from 1 - 100”
continue
fi

if [ $guess -lt $num ]


then
echo “Im sorry your guess is too low”
continue
elif [ $guess -gt $num ]
then
echo “Im sorry your guess is too high”
continue
else
echo “Correct, the number was $num”
break
fi
done

3. text_conversion.sh

#!/bin/bash
find . -type f -name "*.txt" | while read file; do
filename=$(basename "$file" .txt)
new_filename="$filename.text"
mv "$file" "$new_filename"
done

You might also like