NOTE: This is NOT about how to ssh into a certain directory (that question has been answered many, many times). This is about the proper use of variables in ssh'ing aliases.
I have a directory that I'm working inside of called /the/full/path/to/my/local/working/directory
and on my server at work (that I share with others so no rerouting via cd commands in .bash_login
or .bashrc
allowed on the server), I have a directory called ~/myname/working/directory
.
Since these two (after local
and myname
in the pathname) are mirror images of each other, I would like to write a line in my local .bashrc
so that when I ssh
in, it detects what directory I'm in on my local machine and sends me to the mirror.
So far I have:
GRND=$(cut -d/ -f8- <<< "$PWD")
#<-This returns 'working/directory/'
alias zxc="ssh -t xxx@xxx.xxx.xxx 'cd myname/\"${GRND}\";bash'"
For some reason it's not liking how I'm using the variable GRND
. I tried messing with single quotes and double quotes and even added backslashes so I could nest double-quotes but to no avail.
As of right now it sends me to xxx@xxx.xxx.xxx:~/myname and then opens bash.