See Ash Code logo See Ash Code

Fish did not behave like my Bash subprocess

Ashlynn Antrobus
• • 3 min read

My Bash backend kept one subprocess alive and sent it commands over stdin. Reusing that arrangement for Fish looked reasonable until I tried the real binary.

The pipe stayed open so the next command could use it. In the Fish invocation I was using, that also meant the current command didn’t execute: Fish waited for EOF. A sentinel at the end of the command couldn’t help if the shell hadn’t started running the script.

The July 11 repair changed the backend’s lifetime. Each call now gets a fresh fish --no-config -c <script> process.

There is less state in a fresh process

With persistent Bash, changing directory changes the live shell. The next command inherits that directory because it’s running in the same process.

The Fish backend has to carry the directory itself. It starts the child with cwd=self._cwd, reads the final directory from the completion marker, and saves that directory for the next call.

A dragon carries a folder between two fish in separate bowls, each with a terminal in a thought bubble.

That only preserves the state I explicitly implemented. A variable, function or alias created inside one Fish child doesn’t automatically appear in the next child. Exporting a variable doesn’t send it backwards into the Python parent either.

I replayed the state changes against the archived backends

For a fresh check of this behavior, I ran the code at that revision with Bash and an isolated Fish 3.7.0 binary. These are reproduction results, rather than the original July test logs.

Each row below represents a separate execute() call. The temporary directory name is shortened for readability. Assignment uses each shell’s syntax; the other commands are identical.

CallBashFish
cd /tmp/blog-shell-state-…SuccessSuccess
pwdThe temporary directoryThe temporary directory
Set a variableBLOG_SERIES_STATE=keptset -g BLOG_SERIES_STATE kept
printf '%s\n' "$BLOG_SERIES_STATE"kept and a newlineAn empty line

Both backends returned the same tracked directory. Only Bash retained the variable. The Fish assignment itself succeeded; its process then exited, taking that variable with it.

The shared interface needs to explain that difference

The Bash terminal repair dealt with a persistent child taking control of the parent’s terminal. Fish’s repair changes a more basic assumption: there isn’t a persistent child between commands.

I can return stdout, stderr, exit status and cwd from either backend, even when the shell has already exited.

When I need a Fish variable or function for several commands, I can put them in one script so they share a process.

AA

Written by Ashlynn Antrobus

Software developer, author, and builder. Sharing technical lessons learned from building tools like Ebook2Text, IndexedDict, and rag-mcp, and navigating life as a programmer with dyslexia.