bun icon indicating copy to clipboard operation
bun copied to clipboard

Bun shell ignores 'exit' command

Open ExogenSoftware opened this issue 5 months ago • 2 comments
trafficstars

What version of Bun is running?

1.2.16+631e67484

What platform is your computer?

Linux 6.1.0-18-amd64 x86_64 unknown

What steps can reproduce the bug?

import { $ } from "bun"

await $`
    echo "Good Bun!"
    exit
    exit 0
    exit 1
    echo "Bad Bun!"
`

bun test.js

#!/usr/bin/env bun

echo "Good Bun!"
#Implicit EXIT_SUCCESS
exit
#Explicit EXIT_SUCCESS
exit 0
#Explicit EXIT_FAILURE
exit 1
echo "Bad Bun!"

bun test.sh

OR

chmod +x test.sh ./test.sh

What is the expected behavior?

"Good Bun!"

What do you see instead?

"Good Bun!" "Bad Bun!"

Additional information

I truly thought I was going insane with this one, and it has major implications for unwanted side effects by falling through exit conditions! I even checked the shell documentation and verified that exit was listed as a built-in command.

ExogenSoftware avatar Jun 13 '25 06:06 ExogenSoftware