我可以用 Python 来做到这一点:
def one(arg1):
return arg1
def two(a,b):
result=a+b
return one(result)
two(1,3)
它会起作用。但是如何在 Bash 脚本中执行相同操作?
答案1
尝试通过以下方式传递该参数:
#!/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