Reputation: 63546
I've created a git repository for my .bashrc that I pull from in my local machine and a remote machine. I want to run some commands for my localhost and not for my remote host.
Upvotes: 1
Views: 663
Reputation: 531055
Since you are asking about .bashrc
in particular, may I assume you are using bash
? bash
already sets the parameter HOSTNAME
automatically.
Upvotes: 0
Reputation: 5952
For a more general solution, which:
file pattern matching
for the hostnamesyou may use this idiom:
#!/bin/bash
HOST=`hostname`
case "$HOST" in
# examples of prefix matches:
host1*) echo this matches host1 ;;
host2*) echo this matches host2 ;;
# and so on...
# if none matched you use the default '*' pattern
# which matches everything else
*) echo none matched: hostname is $HOST ;;
esac
Upvotes: 0
Reputation: 63546
This worked for me:
HOSTNAME=$(hostname)
if [ ${HOSTNAME} == "ros-mbp.local" ]; then
echo "host is local"
elif [ ${HOSTNAME} == "dev843.prn1.facebook.com" ]; then
echo "host is remote"
else
echo "host doesn't match."
fi
Upvotes: 3