OS Practical-1
OS Practical-1
2.1. cd .. :-
Path=$ cd ..
Path=$ whoami
(Word count)
Path= $ wc ls.txt
Aim: Write a shell script to validate the entered date. (eg. Date format is:
dd-mm-yyyy).
Code:
read -p "Enter a date (dd-mm-yyyy): " date_input
IFS='-' read -r day month year <<< "$date_input"
if [[ -n $day && -n $month && -n $year && $day =~ ^[0-9]+$ && $month =~ ^[0-9]+$ && $year
=~ ^[0-9]+$ ]]; then
if date -d "$year-$month-$day" >/dev/null 2>&1; then
echo "Valid date."
else
echo "Invalid date."
fi
else
echo "Invalid format. Please enter the date in dd-mm-yyyy format."
Fi
Practical – 5
Aim: Write a shell script to check entered string is palindrome or not.
Code:
read -p "Enter a string: " input_str
input_str=$(echo "$input_str" | tr 'A-Z' 'a-z')
reversed_str=""
for (( i=${#input_str}-1; i>=0; i-- )); do
reversed_str+="${input_str:$i:1}"
done
if [[ "$input_str" == "$reversed_str" ]]; then
echo "The string is a palindrome."
else
echo "The string is not a palindrome."
Fi