6月 072017
 

不惑: shell函数中可以使用return语句提前返回

疑惑:有些shell脚本中,函数外也会出现return;有些shell脚本中在函数外写return就执行失败

参考:

解惑:

  1. 函数中可以使用return语句
  2. 被引用的脚本(就是source 或 dot 方式执行的脚本)中函数外也可以使用return; 使用 sh script.sh 方式执行的script.sh 中不能出现函数外的return语句; 即: 如果在函数外使用return语句,你要清楚你的脚本是用来被source的,而不是被 sh 的;
  3. 其他情况下的return语句将返回失败
 Posted by at 下午 3:24

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据