[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Can someone explain this?
From: |
Dennis Williamson |
Subject: |
Re: Can someone explain this? |
Date: |
Fri, 11 Feb 2011 22:42:22 -0600 |
On Fri, Feb 11, 2011 at 10:28 PM, Jon Seymour <jon.seymour@gmail.com> wrote:
> Ok, so it relates to how ssh interprets its command argument:
>
> So:
>
> bash -c 'cd /tmp ; pwd'
>
> My expectation was that it would invoke bash with the arguments:
>
> '-c'
> 'cd /tmp; pwd'
>
> But bash is actually invoked with:
>
> '-c'
> 'cd'
> '/tmp'
>
> and then pwd is invoked, presumably in same shell that invoked bash.
>
> This can be seen with this:
>
> jseymour@ubuntu:~$ ssh localhost bash -c 'echo\ \$\$\ \$PPID' ';' echo '$$'
> 11553 11552
> 11552
>
> bash is invoked with:
> '-c'
> 'echo $$ $PPID'
>
> then:
>
> echo $$ runs in the parent shell
>
> jon.
>
>
> On Sat, Feb 12, 2011 at 2:44 PM, Dennis Williamson
> <dennistwilliamson@gmail.com> wrote:
>> On Fri, Feb 11, 2011 at 9:21 PM, Jon Seymour <jon.seymour@gmail.com> wrote:
>>> Correction - a _leading_ cd command and only a leading cd command,
>>> seems to be completely ignored in the case I described.
>>>
>>> Why is this?
>>>
>>> jon.
>>>
>>> ---------- Forwarded message ----------
>>> From: Jon Seymour <jon.seymour@gmail.com>
>>> Date: Sat, Feb 12, 2011 at 2:18 PM
>>> Subject: Can someone explain this?
>>> To: bug-bash@gnu.org
>>>
>>>
>>> Can someone explain why this is happening?
>>>
>>> #expected
>>> $ bash -c 'cd /tmp; pwd'
>>> /tmp
>>>
>>> #expected
>>> $ bash -c 'pwd; cd /tmp; pwd'
>>> /home/jseymour
>>> /tmp
>>>
>>> #expected
>>> $ ssh localhost bash -c 'pwd; cd /tmp; pwd'
>>> /home/jseymour
>>> /tmp
>>>
>>> #unexpected
>>> $ ssh localhost bash -c 'cd /tmp; pwd'
>>> /home/jseymour
>>>
>>> My expectation is that the last command should print:
>>>
>>> /tmp
>>>
>>> But, instead, the cd command seems to be completely ignored when bash
>>> is run under ssh. I have reproduced this with bash 4.1.5 on Linux and
>>> bash 3.0.0 on AIX.
>>>
>>> jon.
>>>
>>>
>>
>> It's not particular to Bash. I can reproduce it in several other shells.
>>
>
Yes, do your quoting like this:
ssh localhost 'bash -c "cd /tmp; pwd"'
and your test would look like this:
$ ssh localhost 'bash -c "echo $$; echo \$\$; cd /tmp; pwd"'; echo $$
6324
6324
/tmp
6370
or this:
$ ssh localhost 'echo $$; bash -c "echo $$; echo \$\$; cd /tmp; pwd"'; echo $$
6523
6523
6524
/tmp
6370
Notice what happens with the PIDs when a shell has to be started
before Bash is explicitly started.
- Can someone explain this?, Jon Seymour, 2011/02/11
- Re: Can someone explain this?, Jon Seymour, 2011/02/11
- Re: Can someone explain this?, Dennis Williamson, 2011/02/11
- Re: Can someone explain this?, Jon Seymour, 2011/02/11
- Re: Can someone explain this?,
Dennis Williamson <=
- Re: Can someone explain this?, Bob Proulx, 2011/02/12
- Re: Can someone explain this?, Jon Seymour, 2011/02/12
- Re: Can someone explain this?, Andreas Schwab, 2011/02/12
- Re: Can someone explain this?, Maarten Billemont, 2011/02/12