zsh-users
 help / color / mirror / code / Atom feed
* conflict of "exec zsh" with scp
@ 2008-01-08 22:01 Andy Spiegl
  2008-01-09  0:10 ` Casper Gripenberg
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Andy Spiegl @ 2008-01-08 22:01 UTC (permalink / raw)
  To: ZSH User List

At work all my colleagues prefer bash (I couldn't convince them yet *sigh*).
But I can't live without zsh anymore.  So I put the following into .bashrc:

 if [[ "$REALUSER" == "Andy Spiegl" ]]; then
   which zsh >/dev/null 2>&1 && exec zsh -l
 fi

(the environment variable is coming from .ssh/authorized_keys)

This works great but now scp doesn't work anymore:
 lama:~>scp foo otherhost:
 stty: standard input: Invalid argument
 [1]    19108 exit 1     scp -C foo otherhost:

Any idea how to distinguish my ssh-connects from scp-connects in .bashrc?

Thanks a lot,
 Andy.

-- 
 "Good literature is about Love and War."
 "Junk fiction is about Sex and Violence."


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-08 22:01 conflict of "exec zsh" with scp Andy Spiegl
@ 2008-01-09  0:10 ` Casper Gripenberg
  2008-01-09 17:05   ` Andy Spiegl
  2008-01-09  5:01 ` Bart Schaefer
  2008-01-10 21:27 ` Vincent Lefevre
  2 siblings, 1 reply; 14+ messages in thread
From: Casper Gripenberg @ 2008-01-09  0:10 UTC (permalink / raw)
  To: ZSH User List

Andy Spiegl wrote:
> At work all my colleagues prefer bash (I couldn't convince them yet *sigh*).
> But I can't live without zsh anymore.  So I put the following into .bashrc:
> 
>  if [[ "$REALUSER" == "Andy Spiegl" ]]; then
>    which zsh >/dev/null 2>&1 && exec zsh -l
>  fi
> 
> (the environment variable is coming from .ssh/authorized_keys)
> 
> This works great but now scp doesn't work anymore:
>  lama:~>scp foo otherhost:
>  stty: standard input: Invalid argument
>  [1]    19108 exit 1     scp -C foo otherhost:
> 
> Any idea how to distinguish my ssh-connects from scp-connects in .bashrc?

Why don't you just chsh (man chsh) on your host instead of
doing .bashrc trickery? You all share the same shell account
on a single host?

You could also try to test the bash interactivity flag, and only
run zsh of it's set. Have not tried it myself, but here's a
snippet from the bash manual:

        An interactive shell is  one  started  without  non-option
        arguments  and  without the -c option whose standard input
        and output are both connected to terminals (as  determined
        by  isatty(3)), or one started with the -i option.  PS1 is
        set and $- includes i if bash is interactive,  allowing  a
        shell script or a startup file to test this state.

Casper

> Thanks a lot,
>  Andy.
> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-08 22:01 conflict of "exec zsh" with scp Andy Spiegl
  2008-01-09  0:10 ` Casper Gripenberg
@ 2008-01-09  5:01 ` Bart Schaefer
  2008-01-09  7:34   ` Bart Schaefer
  2008-01-10 21:27 ` Vincent Lefevre
  2 siblings, 1 reply; 14+ messages in thread
From: Bart Schaefer @ 2008-01-09  5:01 UTC (permalink / raw)
  To: ZSH User List

On Jan 8, 11:01pm, Andy Spiegl wrote:
}
} But I can't live without zsh anymore.  So I put the following into .bashrc:
} 
}  if [[ "$REALUSER" == "Andy Spiegl" ]]; then
}    which zsh >/dev/null 2>&1 && exec zsh -l
}  fi

The first thing I'd try is changing from

	exec zsh -l

to

	exec zsh -$- "$@"

However, if want you really want is to NOT exec zsh for scp, then it may
be sufficient to change the test to:

	[[ ! -t 0 && "$REALUSER" == "Andy Spiegl" ]]

Alternately, to implement Casper's suggestion:

	[[ "$-" != *i* && "$REALUSER" == "Andy Spiegl" ]]


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-09  5:01 ` Bart Schaefer
@ 2008-01-09  7:34   ` Bart Schaefer
  0 siblings, 0 replies; 14+ messages in thread
From: Bart Schaefer @ 2008-01-09  7:34 UTC (permalink / raw)
  To: ZSH User List

On Jan 8,  9:01pm, Bart Schaefer wrote:
}
} Alternately, to implement Casper's suggestion:
} 
} 	[[ "$-" != *i* && "$REALUSER" == "Andy Spiegl" ]]

Just noticed that I typo'd that -- should be == not != ...


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-09  0:10 ` Casper Gripenberg
@ 2008-01-09 17:05   ` Andy Spiegl
  2008-01-10  2:21     ` Bart Schaefer
  0 siblings, 1 reply; 14+ messages in thread
From: Andy Spiegl @ 2008-01-09 17:05 UTC (permalink / raw)
  To: ZSH User List

Casper wrote:
> Why don't you just chsh (man chsh) on your host instead of
> doing .bashrc trickery? You all share the same shell account
> on a single host?
Yes, I was talking about a "shared" admin and/or root account.

Bart wrote: 
> The first thing I'd try is changing from
> 	exec zsh -l
> to
> 	exec zsh -$- "$@"
Good idea, thanks!
But apparently that's not enough:
 lama:~>scp admin@otherhost:/etc/passwd .
 zsh: string expected after -c
 [1]    31295 exit 1     scp -C admin@otherhost:/etc/passwd .


> However, if want you really want is to NOT exec zsh for scp, then it may
> be sufficient to change the test to:
>
> 	[[ ! -t 0 && "$REALUSER" == "Andy Spiegl" ]]
Without the "!" it works.

> Alternately, to implement Casper's suggestion:
> [[ "$-" == *i* && "$REALUSER" == "Andy Spiegl" ]]
Works, too, thanks a lot!

But why did you mention whether I really don't want to use zsh for scp?
Is there any disadvantage?  Actually I don't care as long as it works
as expected. :-)  But of course I'd prefer using zsh instead of bash
as I do when using my personal accounts, too.

Thanks,
 Andy.

-- 
 Unable to locate coffee, operator halted


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-09 17:05   ` Andy Spiegl
@ 2008-01-10  2:21     ` Bart Schaefer
  2008-01-10  9:51       ` Andy Spiegl
  0 siblings, 1 reply; 14+ messages in thread
From: Bart Schaefer @ 2008-01-10  2:21 UTC (permalink / raw)
  To: ZSH User List

On Jan 9,  6:05pm, Andy Spiegl wrote:
}
} > However, if want you really want is to NOT exec zsh for scp, then it may
} > be sufficient to change the test to:
} >
} > 	[[ ! -t 0 && "$REALUSER" == "Andy Spiegl" ]]
} Without the "!" it works.

Yes, I don't know why I had my head on backwards for that message.

} But why did you mention whether I really don't want to use zsh for scp?
} Is there any disadvantage?

As you're in a shared environment, it's conceivable that there are other
scripts that might run scp or a non-interactive ssh and depend on bash
semantics on the far end.

The main reason to care one way or the other is globbing.  If you pass a
glob pattern to the remote system (which only makes sense if the remote
system is the source of the copy, really), you'll be restricted to bash
patterns unless you can figure out how to get zsh to run.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-10  2:21     ` Bart Schaefer
@ 2008-01-10  9:51       ` Andy Spiegl
  2008-01-10 15:52         ` Bart Schaefer
  0 siblings, 1 reply; 14+ messages in thread
From: Andy Spiegl @ 2008-01-10  9:51 UTC (permalink / raw)
  To: ZSH User List

Bart Schaefer wrote:

> Yes, I don't know why I had my head on backwards for that message.
:-)

> The main reason to care one way or the other is globbing.  If you pass a
> glob pattern to the remote system (which only makes sense if the remote
> system is the source of the copy, really), you'll be restricted to bash
> patterns unless you can figure out how to get zsh to run.
Ahhh, thanks for the explanation!

So if I want zsh to run for non-interactive shells, how would I do that?
Putting
 exec zsh -$- "$@"
into .bashrc only leads to:

 lama:~>scp admin@otherhost:/etc/passwd .
 zsh: string expected after -c
 [1]    31295 exit 1     scp -C admin@otherhost:/etc/passwd .

Thanks,
 Andy.

-- 
 cogito ergo sum, bibo ergo sum, cogito ergo bib, bibo ergo bib?


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-10  9:51       ` Andy Spiegl
@ 2008-01-10 15:52         ` Bart Schaefer
  2008-01-16 12:00           ` Andy Spiegl
  0 siblings, 1 reply; 14+ messages in thread
From: Bart Schaefer @ 2008-01-10 15:52 UTC (permalink / raw)
  To: ZSH User List

On Jan 10, 10:51am, Andy Spiegl wrote:
}
} So if I want zsh to run for non-interactive shells, how would I do that?

It may not be possible.

} Putting
}  exec zsh -$- "$@"
} into .bashrc only leads to:
} 
}  lama:~>scp admin@otherhost:/etc/passwd .
}  zsh: string expected after -c

That indicates that the command passed to "sh -c ..." is not available
to be passed along to the new shell that's exec'd.  Which makes sense
now that I think about it, because "$@" will be any additional args
that came after the command for -c.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-08 22:01 conflict of "exec zsh" with scp Andy Spiegl
  2008-01-09  0:10 ` Casper Gripenberg
  2008-01-09  5:01 ` Bart Schaefer
@ 2008-01-10 21:27 ` Vincent Lefevre
  2008-01-10 22:10   ` Anonymous bin ich
  2008-01-16 12:36   ` Andy Spiegl
  2 siblings, 2 replies; 14+ messages in thread
From: Vincent Lefevre @ 2008-01-10 21:27 UTC (permalink / raw)
  To: ZSH User List

On 2008-01-08 23:01:02 +0100, Andy Spiegl wrote:
> At work all my colleagues prefer bash (I couldn't convince them yet *sigh*).
> But I can't live without zsh anymore.  So I put the following into .bashrc:
> 
>  if [[ "$REALUSER" == "Andy Spiegl" ]]; then
>    which zsh >/dev/null 2>&1 && exec zsh -l
>  fi

It's better to put that in your .bash_profile (instead of .bashrc) so
that it is executed only by login shells. This is what I do.

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-10 21:27 ` Vincent Lefevre
@ 2008-01-10 22:10   ` Anonymous bin ich
  2008-01-11 21:29     ` Vincent Lefevre
  2008-01-16 12:36   ` Andy Spiegl
  1 sibling, 1 reply; 14+ messages in thread
From: Anonymous bin ich @ 2008-01-10 22:10 UTC (permalink / raw)
  To: ZSH User List

You might be able to rectify problem once and for all by having
something like this before your .bashrc:

if [ -n "$(echo $- | grep i)" ]; then
  if [[ "$REALUSER" == "Andy Spiegl" ]]; then
    which zsh >/dev/null 2>&1 && exec zsh -l
  fi
fi


On Jan 10, 2008 10:27 PM, Vincent Lefevre <vincent@vinc17.org> wrote:
> On 2008-01-08 23:01:02 +0100, Andy Spiegl wrote:
> > At work all my colleagues prefer bash (I couldn't convince them yet *sigh*).
> > But I can't live without zsh anymore.  So I put the following into .bashrc:
> >
> >  if [[ "$REALUSER" == "Andy Spiegl" ]]; then
> >    which zsh >/dev/null 2>&1 && exec zsh -l
> >  fi
>
> It's better to put that in your .bash_profile (instead of .bashrc) so
> that it is executed only by login shells. This is what I do.
>
> --
> Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
> 100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
> Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)
>



-- 
Regards,

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-10 22:10   ` Anonymous bin ich
@ 2008-01-11 21:29     ` Vincent Lefevre
  0 siblings, 0 replies; 14+ messages in thread
From: Vincent Lefevre @ 2008-01-11 21:29 UTC (permalink / raw)
  To: ZSH User List

On 2008-01-10 23:10:48 +0100, Anonymous bin ich wrote:
> You might be able to rectify problem once and for all by having
> something like this before your .bashrc:
> 
> if [ -n "$(echo $- | grep i)" ]; then
>   if [[ "$REALUSER" == "Andy Spiegl" ]]; then
>     which zsh >/dev/null 2>&1 && exec zsh -l
>   fi
> fi

This would have the effect to run zsh when one types bash from zsh.
This is bad as one may want to be able to use bash even though the
preferred login shell is zsh.

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-10 15:52         ` Bart Schaefer
@ 2008-01-16 12:00           ` Andy Spiegl
  2008-01-16 16:03             ` Bart Schaefer
  0 siblings, 1 reply; 14+ messages in thread
From: Andy Spiegl @ 2008-01-16 12:00 UTC (permalink / raw)
  To: ZSH User List

Bart Schaefer wrote:
> } Putting
> }  exec zsh -$- "$@"
> } into .bashrc only leads to:
> } 
> }  lama:~>scp admin@otherhost:/etc/passwd .
> }  zsh: string expected after -c
> 
> That indicates that the command passed to "sh -c ..." is not available
> to be passed along to the new shell that's exec'd.  Which makes sense
> now that I think about it, because "$@" will be any additional args
> that came after the command for -c.

Uhm, I can't follow you (yet).  If $@ contains the additional args, why
isn't zsh -$- "$@" enough then?

Thx,
 Andy.

-- 
 You will find that the State is the kind of organization which, while it does
 big things badly, does small things badly too.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-10 21:27 ` Vincent Lefevre
  2008-01-10 22:10   ` Anonymous bin ich
@ 2008-01-16 12:36   ` Andy Spiegl
  1 sibling, 0 replies; 14+ messages in thread
From: Andy Spiegl @ 2008-01-16 12:36 UTC (permalink / raw)
  To: ZSH User List

Vincent Lefevre wrote:

> >  if [[ "$REALUSER" == "Andy Spiegl" ]]; then
> >    which zsh >/dev/null 2>&1 && exec zsh -l
> >  fi
> 
> It's better to put that in your .bash_profile (instead of .bashrc) so
> that it is executed only by login shells. This is what I do.

VERY good idea!  As .bash_profile is only executed for login shells
I don't even need the test for an interactive shell anymore.
 if [[ "$-" == *i* ]; then ...

Thanks,
 Andy.

-- 
 Some say time is the fire in which we burn  -- Dr. Soren


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: conflict of "exec zsh" with scp
  2008-01-16 12:00           ` Andy Spiegl
@ 2008-01-16 16:03             ` Bart Schaefer
  0 siblings, 0 replies; 14+ messages in thread
From: Bart Schaefer @ 2008-01-16 16:03 UTC (permalink / raw)
  To: ZSH User List

On Jan 16,  1:00pm, Andy Spiegl wrote:
} Subject: Re: conflict of "exec zsh" with scp
}
} Bart Schaefer wrote:
} > }  lama:~>scp admin@otherhost:/etc/passwd .
} > }  zsh: string expected after -c
} > 
} > That indicates that the command passed to "sh -c ..." is not available
} 
} Uhm, I can't follow you (yet).  If $@ contains the additional args, why
} isn't zsh -$- "$@" enough then?

Try this:

    bash -c 'print zsh -$- "$@"' more args here

Note that neither the "-c ..." nor the word "more" are printed.  Both
of those are needed to correctly excute a new shell for the command that
scp originally passed to bash, but you can't get at them.


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2008-01-16 16:03 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-08 22:01 conflict of "exec zsh" with scp Andy Spiegl
2008-01-09  0:10 ` Casper Gripenberg
2008-01-09 17:05   ` Andy Spiegl
2008-01-10  2:21     ` Bart Schaefer
2008-01-10  9:51       ` Andy Spiegl
2008-01-10 15:52         ` Bart Schaefer
2008-01-16 12:00           ` Andy Spiegl
2008-01-16 16:03             ` Bart Schaefer
2008-01-09  5:01 ` Bart Schaefer
2008-01-09  7:34   ` Bart Schaefer
2008-01-10 21:27 ` Vincent Lefevre
2008-01-10 22:10   ` Anonymous bin ich
2008-01-11 21:29     ` Vincent Lefevre
2008-01-16 12:36   ` Andy Spiegl

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).