Sort
In this challenge, you are tasked with creating a script that sorts a given set of numbers in either ascending or descending order using the bubble sort mechanism. This challenge aims to enhance your understanding of sorting mechanisms and improve your ability to work with arrays.
Tasks
You need to complete the following tasks:
- Write a script named
sort.sh
.
- Pass numbers through command-line arguments.
- Provide a menu for the user to choose ascending or descending.
- Show the sorted array according to the user's choice.
Requirements
You must meet the following requirements:
- The script should be named
sort.sh
.
- Accept numbers as command-line arguments.
- Prompt the user to choose between ascending or descending order.
- Sort the array according to the user's choice and display the sorted result.
Example
labex:project/ $ bash sort.sh 1 5 4 3 6
inputcount : 5
content of inputValue 1 5 4 3 6
[Input] Enter your choice [Input]
1.Ascending
2.Descending
1
[OUTPUT] Ascending Order [OUTPUT]
1 3 4 5 6
labex:project/ $ bash sort.sh 1 5 4 3 6
inputcount : 5
content of inputValue 1 5 4 3 6
[Input] Enter your choice [Input]
1.Ascending
2.Descending
2
[OUTPUT] Descending Order [OUTPUT]
6 5 4 3 1