bash - Is there a command that works for command line arguments like the sort command does for files? -
i trying write script in bash take between 1 , 5 command line arguments user , report them in reverse numerical order standard output. command know work sort command, works files. there similar command sorting command line arguments? here have far.
#!/bin/bash if [ $# -lt 1 ] || [ $# -gt 5 ]; echo "incorrect number of arguments!" else sorted=sort -rn $* echo "sorted: $sorted" fi
try:
sorted=$( printf '%s\n' "$@" | sort -rn ) printf '%s\n' "${sorted//$'\n'/ }"
Comments
Post a Comment