Added Endsem Questions
This commit is contained in:
parent
6ff1894732
commit
d46358f2da
2 changed files with 169 additions and 0 deletions
48
OS/endsem/bashq.sh
Normal file
48
OS/endsem/bashq.sh
Normal file
|
@ -0,0 +1,48 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Ask for the directory
|
||||
echo "Enter directory path:"
|
||||
read dir
|
||||
|
||||
while true; do
|
||||
echo ""
|
||||
echo "Menu:"
|
||||
echo "1. Convert .txt files to .py in $dir"
|
||||
echo "2. List ownership properties (ls -l) of all files in $dir"
|
||||
echo "3. Count .sh files and subdirectories in $dir"
|
||||
echo "4. Exit"
|
||||
echo -n "Choose an option: "
|
||||
read option
|
||||
|
||||
case $option in
|
||||
1)
|
||||
for file in "$dir"/*.txt; do
|
||||
if [ -f "$file" ]; then
|
||||
new="${file%.txt}.py"
|
||||
mv "$file" "$new"
|
||||
echo "Renamed: $file -> $new"
|
||||
fi
|
||||
done
|
||||
;;
|
||||
2)
|
||||
ls -l "$dir"
|
||||
;;
|
||||
3)
|
||||
# Count .sh files in the given directory (errors hidden if none found)
|
||||
sh_count=$(ls -1 "$dir"/*.sh 2>/dev/null | wc -l)
|
||||
# Count subdirectories (using a trailing slash pattern)
|
||||
dir_count=$(ls -d "$dir"/*/ 2>/dev/null | wc -w)
|
||||
echo ".sh file count: $sh_count"
|
||||
echo "Subdirectory count: $dir_count"
|
||||
;;
|
||||
4)
|
||||
echo "Exiting..."
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option. Please try again."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "Bye!"
|
Loading…
Add table
Add a link
Reference in a new issue