Practical No12 - Rohit
Practical No12 - Rohit
# Check if it is a directory
if [ -d "$file_name" ]; then
echo "$file_name is a directory."
else
echo "$file_name is not a directory."
fi
else
echo "$file_name does not exist."
fi
Ex 3-A
file=abc.txt
if [ ! -f "$forloop.sh" ]; then
echo "$forloop.sh"
fi
Ex 3-B
file="abc.txt"
Ex 3-C
# Define the file name
file="abc.txt"
Ex12_1
read -p "Enter the source file name: " source_file
read -p "Enter the destination file name: " destination_file
if [ -f "$path" ]; then
echo "$path is a regular file."
echo "Choose an action:"
echo "1) Copy"
echo "2) Remove"
echo "3) Rename"
read -p "Enter your choice (1-3): " choice
case $choice in
1)
read -p "Enter the destination file name: " dest_file
cp "$path" "$dest_file"
echo "Copied $path to $dest_file."
;;
2)
rm "$path"
echo "Removed $path."
;;
3)
read -p "Enter the new name for the file: " new_name
mv "$path" "$new_name"
echo "Renamed $path to $new_name."
;;
*)
echo "Invalid choice."
;;
esac
elif [ -d "$path" ]; then
echo "$path is a directory."
else
echo "$path does not exist."
fi