Nav
Nav

Reputation: 20658

Having aliases active in a terminal session without using bashrc or bash_profile or bash_aliases?

This question is an offshoot of my question on whether there's anything wrong with having aliases on a production server.

So I tried creating a shell script with some aliases

#!/bin/sh
echo "creating aliases..."
alias f='clear;cd ..;ls;pwd'
alias ff='clear;cd ../..;ls;pwd'

Did a chmod +x al.sh, and ran the script ./al.sh, but although the "creating aliases..." statement got printed, none of the aliases worked, because they were obviously active only until the script ran.

So is there a way I can run a script containing the aliases I want, which will remain active as long as the terminal session is active? The basic idea being, not to cause problems for colleagues who use the same server.

Upvotes: 1

Views: 57

Answers (1)

fedorqui
fedorqui

Reputation: 289605

For cases when you want to store functions and aliases just for your session, I find it quite useful to have a file with them and sourcing it when I login the server.

So just place it somewhere like:

~/nav_alias_file.sh

And then just after sshing the server type:

source ~/nav_alias_file.sh

Note by the way that, as Sundeep expressed in comments, you do not need the shebang in that file.

Upvotes: 2

Related Questions