[英]Abort from a .bashrc script
I know the .bashrc
script must be run like source .bashrc
or . .bashrc
我知道.bashrc
脚本必须像source .bashrc
一样运行. .bashrc
. .bashrc
so changes in exports are kept during the session, but i need to abort from half the bashrc script without exiting the session. . .bashrc
所以在会话期间保留导出的更改,但是我需要从bashrc脚本的一半中止而不退出会话。
Currently i'm doing a binary search of a point where i issue a command which assumes the existence of a tty. 目前我正在进行二分搜索,我发出一个假定存在tty的命令。 This is to avoid getting the message stdin: is not a tty
. 这是为了避免获取消息stdin: is not a tty
。 So the easiest way is to break the execution of the bashrc script, but i haven't found a way to do so. 所以最简单的方法是打破 bashrc脚本的执行,但我还没有找到办法。
How do i abort from half the execution inside the .bashrc script w/o ending the session ? 如何在结束会话的情况下从.bashrc脚本中的一半执行中止 ? (aka using the exit command) (又名使用exit命令)
You can use the return
command to "exit" your script. 您可以使用return
命令“退出”脚本。 It's usually an error to use return
outside of a function, but you can think of the entire script as a function if it is being source
d. 在函数外部使用return
通常是一个错误,但如果它是source
d,您可以将整个脚本视为一个函数。
what about 关于什么
if [ yourbreakcondition ]; then
...
else
...
The rest of bashrc here
...
fi
Just call return within your bashrc. 只需在bashrc中调用return即可。
Example 例
if [ true ]
then
return
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.