{"id":293,"date":"2023-01-19T14:36:10","date_gmt":"2023-01-19T19:36:10","guid":{"rendered":"https:\/\/blog.signalsguru.net\/?p=293"},"modified":"2023-05-09T19:30:33","modified_gmt":"2023-05-09T23:30:33","slug":"migrating-to-fish-from-bash","status":"publish","type":"post","link":"http:\/\/blog.signalsguru.net\/archives\/293","title":{"rendered":"Migrating to Fish from Bash"},"content":{"rendered":"\n

Overview<\/h2>\n\n\n\n

Switching to the Fish shell<\/a> when you have a bunch of existing Bash scripts can be quite a challenge due incompatibilities with functions and the inability to source scripts from another language. There is at least one plugin which attempts to solve some of these problems, but I have not looked at it. Instead I used the suggested trick below. However, this alone is not enough. It needs a lot more work to make it usable. This replaces the fish shell with a bash shell that runs your script. When the script is done, it replaces the bash shell with a fish shell, leaving you back in fish.<\/p>\n\n\n\n

exec bash -c \"bash_script.sh; exec fish\"<\/code><\/pre>\n\n\n\n

The major problems are that (1) you can’t run bash functions in fish, and (2) you can’t source a bash script into fish, which means any variables set in the bash script will not be available in your fish shell. If you don’t have existing scripts or you only have a small number of them, and they are easy to change, the solution to these two problems is easy: don’t use functions and don’t set variables through sourcing. Since this wasn’t an option for me, I solved the problem by writing all the bash functions to individual scripts, creating wrappers around the functions, and defining a function to export variables that has the same syntax in both fish and bash. Before I go any further, let me say that I strongly recommend, if you have any other option, against doing it this way for the following reasons.<\/p>\n\n\n\n