问题
Do functions not exist in the sh shell? I am trying to convert a bash script to also run in sh and I'm having trouble dumbing down the code. Without functions and arrays, its become difficult to replicate the scripts functionality. Ideally I want to write one script that will run in either shell, not two slightly similar scripts.
回答1:
There are functions in sh
, but the function
keyword is missing. Define your functions as
frobnicate () {
# ....
}
With arrays, you are out of luck.
来源:https://stackoverflow.com/questions/24534477/functions-in-sh-shell