I am developing a simple wrapper script for SSH to do some preprocessing before actually executing SSH (to be exact: load the per-host key with keychain/ssh-agent).
In order to do so, I need to extract the host name from the command line arguments. The wrapper shall support all options accepted by SSH — so my first, simple approch using the last command line parameter does not work if the user intends to run a command non-interactively on the remote side.
Does anybody see a simple shell-only way to get the hostname reliably?
Thanks in advance!
getoptto loop through thessharguments. The first non-option parameter should be eitherhostnameoruser@hostname(wherehostnameis a name, an IP address, or an alias from the ssh configuration file[s]).$(hostname)?