I'm interested in sticking with Bash, but I'm wondering if there are ways to enhance its functionality to mimic some Zsh features. First, can I set up Bash to constantly write and read command history in real-time, like Zsh does? Additionally, can I run Bash scripts smoothly if I'm using Zsh in my terminal emulator, similar to how you can run .bat files from PowerShell in Windows?
5 Answers
Yes, you can run Bash scripts from Zsh simply by calling `bash` directly, or if your script includes a shebang and is executable, you can run it directly just like you would any binary. For example, you can write a script like this in `tmp.sh`:
```bash
#!/bin/bash
echo "Bash version: $BASH_VERSION"
```
Make sure to give it execution permissions, and you can run it without issues!
If you're looking for some cool improvements, check out `ble.sh`. It offers syntax highlighting, enhanced autocompletion, and a Vim editing mode. It’s pretty robust, and after some tweaks, I've found it integrates nicely with the atuin project for better history management.
Sounds interesting, I’ll definitely give it a try!
Just a fun fact: Zsh actually has a Bash emulation mode. But regardless of the shell you use, the shell scripts themselves can remain the same. I always start my scripts with `#!/bin/sh` for compatibility, but switching to a Bash shebang is totally fine too if that’s what you prefer!
That’s the point; if I have to use Zsh, I still want my Bash scripts to run by default.
Honestly, if you’re contemplating these features, why not just switch to Zsh? Most people find it a worthwhile change.
To have Bash write and read command history in real-time, you can set this up: add `PROMPT_COMMAND+=( "history -a; history -n" )` to your configuration. This way, every time a prompt appears, Bash writes new history entries to the file and loads any new ones from other sessions. Just a heads up, you might need to hit enter to trigger the history read in your current session, unlike Zsh which does this automatically. But if you're getting good results from it, that's awesome!
Nice! Didn’t know about using PROMPT_COMMAND as an array. This definitely helps!
I had to enter an empty command too for the history to update. Wonder if Zsh is really as real-time as they say. Regardless, glad it's working!

I always use the shebang at the start of my scripts too; it’s just a good habit!