How do I create a Bash alias?

后端 未结 16 672
一个人的身影
一个人的身影 2020-11-28 17:38

I\'m on OSX and I need to put something like this, alias blah=\"/usr/bin/blah\" in a config file but I don\'t know where the config file is.

16条回答
  •  囚心锁ツ
    2020-11-28 18:12

    To create a permanent alias shortcut, put it in .bash_profile file and point .bashrc file to .bash_profile file. Follow these steps (I am creating an alias command called bnode to run babel transpiler on ES6 code):

    1. Go to terminal command prompt and type “cd” (this will take you to the home directory. Note: even though your programming files may be located on your “D: drive”, your “.bash” files may be located on your “C: drive” )
    2. To see the location of the home directory, type “pwd” (this will show you the home directory path and where the .bash files are probably located)
    3. To see all dot "." files in the home directory, type “ls -la” (this will show ALL files including hidden dot "." files)
    4. You will see 2 files: “.bash_profile” and “.bashrc”
    5. Open .bashrc file in VS Code Editor or your IDE and enter “source ~/.bash_profile” in first line (to point .bashrc file to .bash_profile)
    6. Open .bash_profile file in VS Code Editor and enter “alias bnode='./node_modules/.bin/babel-node'” (to create permanent bnode shortcut to execute as bash command)
    7. Save and close both files
    8. Now open the file you want to execute (index.js) and open in terminal command prompt and run file by using command “bnode index.js”
    9. Now your index.js file will execute but before creating bnode alias in .bash_profile file you would get the error "bash: bnode command not found" and it would not recognize and give errors on some ES6 code.
    10. Helpful link to learn about dotfiles: https://dotfiles.github.io/

    I hope this helps! Good luck!

提交回复
热议问题