I'm trying to make a bash function as follows:
- Will SSH into a server and chdir to ~/projects
- If you pass extra arguments ('git pull'), these will be executed. If not, skip step 2
- Leaves you with a bash shell
Right now, I have this:
function xyz {
ssh -t xyz.com 'cd ~/projects; $*; bash'
}
Using this, running 'xyz' leaves me with a shell at xyz.com:~/projects, just like I want, but running 'xyz git pull' yields the following error:
/usr/bin/git: /usr/bin/git: cannot execute binary file
I'm sure I'm missing something simple, can anyone point me in the right direction?
Thanks!
One explanation would be that /usr/bin/git isn't executable. It could be a shell script without a
#!
line or a binary file that's not right for the host. When you log into the host interactively, you may be using another copy of git somewhere else due to your command path.The error message looks to me like
git
is trying to executegit
. My suspicion is that there is another function or alias that is getting executed.Another potential problem is that it's really hard to get the quoting right when executing a variable. As a quick demonstration of the result of that effect, try this (with the quotation marks) at a shell prompt:
In order to solve your problem, you might try:
You've used a single quote, and variable substitution does not work within single-quoted strings:
You see,
$*
stays as a literal. Use double quotes instead:I believe in your case the
$*
is transferred to the target host "as is" and is substituted there, which executes something in yourprojects
directory.