Is it possible to add a flag to a bash alias you create yourself? e.g.
con -a = 'ssh [email protected]'
con -b = 'ssh [email protected]'
Is it possible to add a flag to a bash alias you create yourself? e.g.
con -a = 'ssh [email protected]'
con -b = 'ssh [email protected]'
Or, use a function instead of an alias:
con() {
local OPTIND svr
while getopts ":ab" option; do
case $option in
a) svr=server1 ;;
b) svr=server2 ;;
?) echo "invalid option: $OPTARG"; return 1 ;;
esac
done
ssh username@${svr}.domain.com
}
con -a
Nope – aliases are simple text substitutions. Use different alias names instead:
alias cona='ssh [email protected]'
alias conb='ssh [email protected]'
EDIT if absolutely must have flags, a function will serve better than an alias – see @glenn-jackmann’s answer.
getopts
loop might be a teensy-weensy bit overkill :). – kopischke May 10 '12 at 19:21