I want to launch sublime from a command line in Mac, using subl filename
. It seems to involve dealing with .bash_profile
. But I didn\'t locate the
Q1. How to check if .bash_profile
exists or not in my mac?
Solution: If you're using macOS 10.14 (Mojave) or below. Then open the Terminal.app. Run the following command to check if the .bash_profile
exists or not in your mac.
if [ -r ~/.bash_profile ];
then
echo "Yes, file exists"
else
echo "No, file does not exists"
fi
After running the above command if you get the following line - "Yes, file exists" printed in your Terminal.app. That means the file exists in your mac.
If you get the following line - "No, file does not exist" printed in your Terminal.app. That means the file does not exist in your mac.
To create a .bash_profile
file in your mac. Run the following command,
touch ~/.bash_profile
To restrict access to the .bash_profile
. Run the following command,
chmod 700 ~/.bash_profile
Q2. I want to launch sublime from a command line in Mac?
Solution: To launch sublime from mac. You can make a symlink to subl
. Assuming you've placed Sublime Text in the Applications folder, and that you have a ~/bin
directory in your path, you can run the following command:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
For more details visit the official sublime documentation
Update I'm on Mac OS Mojave.
Open Terminal.app
and paste bellow line,
(1) touch .bash_profile
(2) open -a TextEdit.app .bash_profile
this will open a blank page in TextEdit.app
, from here you can add,update,delete
code.
I hope this will help someone.
just create a new file - it doesn't come default with your computer. all under your user directory - ex. /Users/username
touch .bash_profile
~/.bash_profile
A typical install of OS X won't create a .bash_profile
for you. When you want to run functions from your command line, this is a must-have.
cd ~/
to go to your home foldertouch .bash_profile
to create your new file..bash_profile
with your favorite editor (or you can just type open -e .bash_profile
to open it in TextEdit.. .bash_profile
to reload .bash_profile
and update any functions you add. Notice the space between the two dots!