Zeist
Zeist

Reputation: 645

Call a function from inside of a bash script in terminal

I have written a function called

random_init()

It takes two parameters username and password.Is there a way to call it from the terminal like this.

$ random init username password

Any help is appreciated.

Upvotes: 0

Views: 166

Answers (2)

Bhuvanesh
Bhuvanesh

Reputation: 1279

Just add the function in your .bashrc file , then you can call like this

random_init 'username' 'password'

Upvotes: 0

Tom Fenech
Tom Fenech

Reputation: 74596

Just source the script in which your function is defined:

. my_script.sh 
# or (bash)
source my_script.sh

Then call your function:

random_init 'username' 'password'

Upvotes: 2

Related Questions