B.Sc Computer Science with Data analytics
Linux and Shell Programming - Lab
Bharathiar University
Program 4- Write a Shell script to sort number in ascending order
Source Code
#!/bin/bash
# Prompt the user to enter numbers
echo "Enter numbers separated by spaces:"
read numbers
# Check if input is provided
if [ -z "$numbers" ]; then
echo "No input provided."
exit 1
fi
# Sort numbers in ascending order
sorted=$(echo "$numbers" | tr ' ' '\n' | sort -n)
# Print sorted numbers
echo "Sorted numbers in ascending order:"
echo "$sorted"
Sample Output:
No comments:
Post a Comment