Based on your reasoning, it follows script modified:
#!/bin/bash
case "$1" in
-r) shuf "$2" ;;
-s) sort "$2" ;;
*) cat -n "$1" ;;
esac
Assuming you have an input file called frutas.txt
with the following content:
Banana
Laranja
Melancia
Limão
Maracujá
Maçã
Uva
Goiaba
Tangerina
Pêssego
1) Shuffling the lines of the input file:
$ ./processador.sh -r frutas.txt
Melancia
Maçã
Pêssego
Maracujá
Goiaba
Banana
Tangerina
Uva
Laranja
Limão
2) Sorting the lines of the input file:
$ ./processador.sh -s frutas.txt
Banana
Goiaba
Laranja
Limão
Maçã
Maracujá
Melancia
Pêssego
Tangerina
Uva
3) Displaying the numbered lines contained in the input file:
$ ./processador.sh frutas.txt
1 Banana
2 Laranja
3 Melancia
4 Limão
5 Maracujá
6 Maçã
7 Uva
8 Goiaba
9 Tangerina
10 Pêssego
Explain better, I couldn’t understand your purpose.
– Alessandro Schneider
I’m trying to put a flag that shows the number of lines intended by the user, for example. /bash.sh -n 5 and with this output will only appear 5 lines or 5 items
– user81007
if you want to show the first 5 use the command
head -n5
if it is the last 5 use thetail -n5
. Would that be?– Alessandro Schneider