0

I am trying to create a simple alias for SSH-ing to a host, like the below:

alias wpessh='ssh $1@$1.ssh.wpengine.net'

I also tried using a function as suggested by other answers here:

function wpessh { ssh "$1"@"$1".ssh.wpengine.net; }
export -f wpessh

But neither has worked.

Input

wpessh mysite

Expected Output (expected command to be run)

ssh mysite@mysite.ssh.wpengine.net
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
wickywills
  • 2,093
  • What shell are you using? What happens if you add an echo for debugging purposes, i.e. function wpessh { echo ssh "$1"@"$1".ssh.wpengine.net; } – Sparhawk Oct 29 '18 at 09:44
  • @Sparhawk I'm just using OSX terminal. If I echo the function as you describe, I receive the SSH usage:[....] – wickywills Oct 29 '18 at 09:59
  • What's the $1 contents when issuing the alias? What's the resulting command (try set -x)? Why the upper case SSH in the error msgs? – RudiC Oct 29 '18 at 10:02
  • check this out https://unix.stackexchange.com/questions/3773/how-to-pass-parameters-to-an-alias it may be helpful – BlackCrystal Oct 29 '18 at 10:05
  • @BlackCrystal I actually already looked through that thread and tried using a function as described in the answers, but I can't get it to work for me here. – wickywills Oct 29 '18 at 10:09
  • did you see one of answers that used $@ instead of $1? – BlackCrystal Oct 29 '18 at 10:11
  • I have no idea why you get that output. It works for me. What about function foo { echo $1 $1 ; }, then foo bar? (Also, again, which shell are you using?) – Sparhawk Oct 29 '18 at 10:12
  • @Sparhawk I'm using whatever is default in OSX Terminal. Bash? – wickywills Oct 29 '18 at 10:15
  • Try echo $0. (And the other suggestion I made.) – Sparhawk Oct 29 '18 at 10:21
  • @Sparhawk Interestingly your foo bar function works for me. Also, echo $0 returns -bash. Still can't see why my SSH function doesn't work though. – wickywills Oct 29 '18 at 10:26
  • Cool, I was testing with bash anyway. Okay, at least we have something working. Can you keep adding bits to get the function closer and closer to my original function in the top comment? Then see when it fails? – Sparhawk Oct 29 '18 at 10:28
  • 1
    @wickywills I executed the function wpessh { echo ssh "$1"@"$1".ssh.wpengine.net; } in my OSX Shell both in bash and zsh and it's working fine. – BarathVutukuri Oct 29 '18 at 10:57
  • @BarathVutukuri I don't understand. I use that function, and all I get returned is the usage for the ssh command (a shorter version of what I receive when running man ssh). I.e. it doesn't actually run the SSH, but if I run the command myself, outside of the function, and replacing the $1's with my domain, then it works fine. – wickywills Oct 29 '18 at 12:16
  • @wickywills maybe ssh is already an alias on your machine; what does alias ssh say? –  Jan 13 '19 at 21:19
  • @UncleBilly -bash: alias: ssh: not found, so nope, not an alias. – wickywills Jan 14 '19 at 07:14

0 Answers0