How to set .bash_profile, if it does not exist yet. I want to launch sublime from a command line in Mac

后端 未结 4 1368
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 15:24

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

相关标签:
4条回答
  • 2020-12-08 15:57

    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

    0 讨论(0)
  • 2020-12-08 16:03

    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.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-12-08 16:09

    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.

    1. Start up Terminal
    2. Type cd ~/ to go to your home folder
    3. Type touch .bash_profile to create your new file.
    4. Edit .bash_profile with your favorite editor (or you can just type open -e .bash_profile to open it in TextEdit.
    5. Type . .bash_profile to reload .bash_profile and update any functions you add. Notice the space between the two dots!
    0 讨论(0)
提交回复
热议问题