My problem is how can I iterate through the command line arguments if the number of allowed arguments is a variable:
example:
./sort.sh n <n integers to sort>
./sort.sh 5 3 4 2 1 5
I tried iterating it through a for-loop and putting it in a .txt file for the sort function but that presents a problem since the delimiter, say i, accepts only constants.
Thanks. 😀
You don’t need the number of arguments. You can get it from within the script with
$#.And you don’t need to loop through the arguments. Just pass them one per line to
sort -n.Something like:
printf "%s\n" $@ | sort -n.