# How do I add a flag to an alias?

Is it possible to add a flag to a bash alias you create yourself? e.g.

con -a = 'ssh username@server1.domain.com'

-

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
}

con -a

-
Right. Though, considering OP only needs a single flag, the getopts loop might be a teensy-weensy bit overkill :). –  kopischke May 10 '12 at 19:21
If you're going to show someone how to do something, show them the correct way. –  glenn jackman May 10 '12 at 20:10
not contesting the merits of your answer – I linked to it indicating it is better than mine. –  kopischke May 10 '12 at 20:12
Can this be placed in .profile along with aliases? –  Ed George May 14 '12 at 11:15
.bashrc is usually recommended –  glenn jackman May 14 '12 at 11:40

Nope – aliases are simple text substitutions. Use different alias names instead:

alias cona='ssh username@server1.domain.com'