0% found this document useful (0 votes)
2 views3 pages

Intermediate Shell Programs

The document contains ten intermediate shell scripting programs that perform various tasks. These include checking for strong passwords, counting hidden files, finding the second largest number, renaming file extensions, counting logged-in users, checking file permissions, reversing a number, displaying a calendar, identifying the largest file in a directory, and checking if a string is a palindrome. Each program includes the necessary code and user prompts for interaction.

Uploaded by

gargtarun505
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)
2 views3 pages

Intermediate Shell Programs

The document contains ten intermediate shell scripting programs that perform various tasks. These include checking for strong passwords, counting hidden files, finding the second largest number, renaming file extensions, counting logged-in users, checking file permissions, reversing a number, displaying a calendar, identifying the largest file in a directory, and checking if a string is a palindrome. Each program includes the necessary code and user prompts for interaction.

Uploaded by

gargtarun505
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

10 Shell Scripting Programs

(Intermediate)
1. Check Strong Password
read -p "Enter password: " pass

if [[ ${#pass} -ge 8 && "$pass" =~ [0-9] && "$pass" =~ [@#$%] ]]

then

echo "Strong Password"

else

echo "Weak Password"

fi

2. Count Hidden Files


count=$(ls -d .* 2>/dev/null | wc -l)

echo "Hidden files: $count"

3. Second Largest Number


echo "Enter numbers:"

read -a arr

sorted=($(printf '%s

' "${arr[@]}" | sort -nr))

echo "Second largest: ${sorted[1]}

4. Rename .txt to .bak


for file in *.txt

do

mv "$file" "${file%.txt}.bak"
done

5. Count Logged-in Users


who | wc -l

6. Check File Permissions


read -p "Enter file name: " file

if [ -r "$file" ]; then echo "Readable"; fi

if [ -w "$file" ]; then echo "Writable"; fi

if [ -x "$file" ]; then echo "Executable"; fi

7. Reverse a Number
read -p "Enter number: " num

rev=0

while [ $num -gt 0 ]

do

rem=$((num % 10))

rev=$((rev * 10 + rem))

num=$((num / 10))

done

echo "Reversed: $rev"

8. Display Calendar
read -p "Enter month: " m

read -p "Enter year: " y


cal $m $y

9. Largest File in Directory


ls -S | head -n 1

10. Palindrome String


read -p "Enter string: " str

rev=$(echo $str | rev)

if [ "$str" = "$rev" ]

then

echo "Palindrome"

else

echo "Not Palindrome"

fi

You might also like