I can do this in Python:
def one(arg1): return arg1 def two(a,b): result=a+b return one(result) two(1,3) And it will work. But how do I do the same in a bash script?
1 Answer
Try that argument passing this way:
#!/usr/bin/env bash function one(){ # Print the result to stdout echo "$1" } function two() { local one=$1 local two=$2 # Do arithmetic and assign the result to # a variable named result result=$((one + two)) # Pass the result of the arithmetic to # the function "one" above and catch it # in the variable $1 one "$result" } # Call the function "two" two 1 3 1