Homebrew asked me to move macports now it does not work
Disentangling messed up dot files and environment variables and paths might be a lot of work if you didn’t follow the recommended steps precisely or made subsequent changes. What about making a list of the homebrew packages you have (if any) then removing it entirely. Same with macports - don’t try to adapt it to run in a new place - remove it entirely after you know what packages you need.

Then make a brand new user account - install homebrew there cleanly with a default path and having cleaned up /opt before you made the new account.

This will quickly let you know if you have a system problem or it’s just the weight of all the changes made to get the previous software to run.

The alternative to this will be a lot of back and forth and you dumping a ton of data into the question or arranging remote access with someone skilled in picking apart bash/scripting errors and digging into the code and what brew doctor has to say about your setup that’s broken.