CodeGuy
CodeGuy

Reputation: 28907

Bash Programming - Creating a Custom Terminal Command - Mac

I tried making a custom command for my terminal. I'm running Mac OS X Version 10.6.6.

Here are the steps I took:

  1. Opened the terminal

  2. Typed "ls -a" and saw a ".bash_profile" file

  3. Typed "vi .bash_profile" and saw that the file was empty

  4. Added the following to the top of the file: "test() { echo hi }"

  5. Saved the vi session by typing ":wq"

Then, I was back to the terminal, and typed "test", however nothing outputted (namely, I didn't see "hi").

So, what am I doing wrong? Thanks!

Upvotes: 9

Views: 8521

Answers (2)

codingishard
codingishard

Reputation: 1

I know this is pretty late, but for future people who google this question, here's what you need to do:

When you edit the bash.profile file, you need to use the alias command. For example: alias [name]="[script]" Since you are trying to make a test command that sends an output of "hi", you would enter test where [name] is, and echo hi where [script] is. Do not forget to use quotations around the script

Upvotes: 0

Laurent G
Laurent G

Reputation: 3184

try to force re-evaluation of file by typing source .bash_profile

Upvotes: 10

Related Questions