Сценарий оболочки Bash для определения наибольшего значения из заданных аргументов командной строки
Опубликовано: 16 Февраля, 2022
Напишите сценарий оболочки, чтобы узнать наибольшее значение из заданного числа аргументов командной строки.
Пример:

Специальные переменные в bash:
$ @ - Все аргументы. $ # - Количество аргументов. $ 0 - Имя файла. $ 1, $ 2, $ 3, $ 4 ... - Конкретные аргументы.
Approach
- If the number of arguments is 0, end the program.
- If not zero, then
- Initialize a variable maxEle with first argument.
- Loop over all the arguments. Compare each argument with maxEle and update it if the argument is greater.
#Check if the number of arguments passed is zeroif [ "$#" = 0 ]then #Script exits if no #arguments passed echo "No arguments passed." exit 1fi #Initialize maxEle with #the first argumentmaxEle=$1 #Loop that compares maxEle with the #passed arguments and updates itfor arg in "$@"do if [ "$arg" -gt "$maxEle" ] then maxEle=$arg fidoneecho "Largest value among the arguments passed is: $maxEle" |