Functions in sh shell

不打扰是莪最后的温柔 提交于 2019-12-24 11:46:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!