The Z shell seems to be eating part of my command after expanding arguments inside a function, but only in very specific cases?
Specifically this is happening if the argument is followed immediately by semicolon-l (:l
). For example, I have this function in my .zshrc (which I would like to use to connect to notebooks on remote servers):
function notebook() {
echo 1: localhost:8888:localhost:8888 aaa
echo 2: localhost:$2:localhost:$2 $1
echo 3: localhost:$2:ocalhost:$2 $1
echo 4: localhost:$2localhost:$2 $1
ssh -N -f -L localhost:$2:localhost:$2 $1
}
The thing I want to run is of course the last line, but I echo 4 other examples in hopes they can help pinpoint the issue: (1) is a hard coded version of the line I want to run - identical, except there are no arguments, (2) is exactly what I want to run, with arguments, (3) is 2 except instead of :localhost
I have :ocalhost
, and (4) is 2 except instead of :localhost
I have localhost
.
When I run notebook aaa 8888
from my terminal, I get the following output:
1: localhost:8888:localhost:8888 aaa
2: localhost:8888ocalhost:8888 aaa
3: localhost:8888:ocalhost:8888 aaa
4: localhost:8888localhost:8888 aaa
Bad local forwarding specification 'localhost:8888ocalhost:8888'
i.e.: (1), (3), and (4) all come out exactly as described in their echos, but (2) comes out with the :l
gone. The same issue seems to happen when the ssh itself is called, causing my computer to complain about bad forwarding.
Why is this happening and how can I fix it? I don't even know what error to search for to describe this!
Thank you!