In the built-in shell, I print echo $(max 15 2) but don't get an answer?
echo $(max 15 2)
Why is this so?
code:
function max { if [ "$1" -eq "$2" ] then return $1 else if [ "$1" -gt "$2" ] then return $1 else return $2 fi fi }
From the comments:
Replace the return with an echo and your code works fine. - blender
The $(...) syntax is specifically designed to give you the output of a command, even if that command is a function call. return in the function is similar to the output for the script as a whole; it sets its status, which is an integer in the range from 0 to 255. (This is very different from other languages ββthat you might get used to, where return is used to return a value from a function.) - Keith Thompson
$(...)
Bash functions are not like functions in other languages. They behave just like any other command: they can accept command line arguments, read from standard input, write to standard output and standard error, and return with exit status. They do not ... strictly speaking - return the calculated value. - chepner
Replace return with echo and your code will work fine.
return
echo
Source: https://habr.com/ru/post/1434147/More articles:How to change flipbox popup window display in jQuery-mobile-datebox mm-dd-yyyy format to dd-mm-yyyy - jqueryThe best way to build a query is sql@AssociationOverride and @AttributeOverride in the new Doctrine 2.3 - doctrineHow to find unused properties in a pump - javaAssociation was not found - ruby-on-railsUsing variables in an array - phpWhy refer to an event through a variable? - c #How to use cascade in Postgresql query when deleting record from parent table - postgresqlhibernate generates invalid sql "select max (id) from my_table" - sqlA dictionary-like data structure. Is this a good practice? - javaAll Articles