tl;dr
To ensure that you open a file in your default text editor using the macOS open
CLI, use:
open -t ~/.bash_profile
Otherwise, if the file needn't be excecutable, run chmod -x <file>
(chmod -x ~/.bash_profile
, in this case) to make open
behave like it did before.
From you question I infer that you're on macOS (OS X).
What the macOS open
CLI does when passed a file depends on the file's suffix (extension), and, in the absence of one, on whether the file has the executable (r
) permissions bit(s) set (if not, the file opens in the standard text editor, which is what you saw before).
A file displaying in red when you use ls -a
(the -a
being necessary to show hidden items such as .bash_profile
), implies that the file is indeed executable by you.
A suffix-less executable (text) file causes open
to run it in a new terminal window as a shell script, which is what you're seeing.
In other words: at some point, unbeknownst to you, executable permissions were assigned to ~/.bash_profile
, which explains the change in behavior.
However, there is no need for ~/.bash_profile
to be executable, because it is sourced by Bash on startup.
As stated above, either remove the executable permissions, or simply use open -t
to open it.