Terminal freezes after "exit" command in bash script

I'm running Terminal Version 2.6.1 on Mac. I'm writing a bash script, and I want to exit the script if a certain condition is met.

I do that with this command:

exit 1

after doing that, the script exits and I see this on the terminal:

Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

After that, my terminal is frozen and I can't do anything with it anymore.

Is there a way to negate having to open up a new terminal each time the script quits?


I am running the script from my terminal like this:

. script.sh

Don't use

. script.sh

to run the script. This runs the script in the same interactive shell that you're using in the Terminal session, and when the script uses exit , that exits the interactive shell as well.

Start the script with this line, which tells the OS to use bash to execute the script:

#!/bin/bash

Give it execute permission with:

chmod 755 script.sh

and then run it with

./script.sh

This runs the script in its own process.

链接地址: http://www.djcxy.com/p/87980.html

上一篇: 如何在bash shell终端输出不同颜色的命令?

下一篇: 终端在bash脚本中的“退出”命令后冻结