#!/bin/bash source someneatscriptthatendsprematurely.sh
我想能够从那个脚本返回,而不破坏主脚本。
使用退出断点的主脚本,返回只在函数中有效,并尝试$(退出1)似乎也不工作。
那么,是否可以返回一个sub-bash脚本而不打破主bash?
任何帮助赞赏!
return [n]
Causes a function to exit with the return value specified by n. If n is omitted,the return status is that of the last command executed in the function body. If used outside a function,but during execution of a script by the . (source) command,it causes the shell to stop executing that script and return either n or the exit status of the last command executed within the script as the exit status of the script. If used outside a function and not during execution of a script by .,the return status is false. Any command associated with the RETURN trap is executed before execution resumes after the function or script.
您可以使用以下两个脚本查看此操作:
script1.sh: . script2.sh echo hello again script2.sh: echo hello return echo goodbye
当您运行script1.sh时,您会看到:
hello hello again