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

Bash Scripts for Number Comparison & File Management

The document contains three Bash scripts: the first script finds the largest of three numbers provided as arguments; the second script converts all .txt files in a specified directory to .py files; and the third script checks if a given file is a symbolic link. Each script includes user prompts and conditional logic to perform its respective function. The document provides usage examples and notes for clarity.

Uploaded by

upendra 7020
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)
3 views2 pages

Bash Scripts for Number Comparison & File Management

The document contains three Bash scripts: the first script finds the largest of three numbers provided as arguments; the second script converts all .txt files in a specified directory to .py files; and the third script checks if a given file is a symbolic link. Each script includes user prompts and conditional logic to perform its respective function. The document provides usage examples and notes for clarity.

Uploaded by

upendra 7020
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

1.

Script to Find the Biggest of 3 Numbers

#!/bin/bash

Big=$1

if [ $2 -gt $Big ]; then


Big=$2
fi

if [ $3 -gt $Big ]; then


Big=$3
fi

echo "Biggest number is $Big"

Run the script like this: ./[Link] 10 25 15

—-----------------------------------------------------------------------------------------------------

2. Script to Convert .txt Files to .py Files in a Directory

#!/bin/bash

echo "Enter the directory name:"


read dir

if [ -d "$dir" ]; then
for file in "$dir"/*.txt; do
[ -e "$file" ] || continue # Skip if no .txt files found
newfile="${file%.txt}.py"
mv "$file" "$newfile"
echo "Renamed $file to $newfile"
done
else
echo "Directory does not exist."
fi

Note: This script renames .txt files to .py in the specified directory.
—--------------------------------------------------------------------------------------------------
3. Script to Check if a File is a Symbolic Link

#!/bin/bash

echo "Enter the file name:"


read file

if [ -L "$file" ]; then
echo "The file is a symbolic link."
else
echo "The file is NOT a symbolic link."
fi
—----------------------------------------------------------------------------------------------------

You might also like