Issue
When I run open .bash_profile
a new terminal opens and
Last login: Wed Nov 30 19:01:22 on ttys004
/Users/MyName/.bash_profile ; exit;
➜ ~ /Users/MyName/.bash_profile ; exit;
[Process completed]
My permissions are
-rwxr-xr-x@ 1 MyName staff 639 Nov 30 19:02 .bash_profile
Also, when I run ls -la
, .bash_profile
is colored red. I don't know why. It wasn't like that before.
All I was trying to do was create an alias, but now I can't even open my .bash_profile
.
Solution
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.
Answered By - mklement0