bash - Running command via ssh also runs .bashrc? -


in reading of bash manpage, .bashrc should executed when shell run interactively. manpage defines interactive as:

an interactive shell 1 started without non-option arguments , without -c option standard input , error both connected terminals (as determined isatty(3)), or 1 started -i option. ps1 set , $- includes if bash interactive, allowing shell script or startup file test state.

yet, executing command ssh causes .bashrc run, contrary expect, given command not run interactively. so, behavior seems bug, seems pervasive on versions of red hat , bash i've tried. can explain why behavior correct?

one additional point: though .bashrc run, $- , $ps set if shell non-interactive (as expect).

$ grep user /etc/passwd user:x:uid:gid:uname:/home/user:/bin/bash  $ cat ~/.bashrc echo bashrc:$-,$ps1  $ bash -c 'echo $-' hbc  $ ssh localhost 'echo $-' </dev/null 2>/dev/null user@localhost's password: bashrc:hbc, hbc  $ ssh localhost 'ps -ef | grep $$' </dev/null 2>/dev/null user@localhost's password: bashrc:hbc, user 28296 28295 0 10:04 ? 00:00:00 bash -c ps -ef | grep $$ user 28297 28296 0 10:04 ? 00:00:00 ps -ef user 28298 28296 0 10:04 ? 00:00:00 grep 28296 

i working around testing [[ $- = *i* ]] in .bashrc, seems if shouldn't have that.

one example server, containing no other files in home directory .bashrc (and .ssh) has configuration:

$ cat /etc/redhat-release red hat enterprise linux server release 5.7 (tikanga)  $ bash --version gnu bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu) copyright (c) 2005 free software foundation, inc. 

versions of bash i've tried on: 3.00.15, 3.1.17, 3.2.25, 4.1.2 (the latter on red hat 6.3).

from bash manual:

bash attempts determine when being run standard input connected network connection, when executed remote shell daemon, rshd, or secure shell daemon sshd. if bash determines being run in fashion, reads , executes commands ~/.bashrc, if file exists , readable. not if invoked sh. --norc option may used inhibit behavior, , --rcfile option may used force file read, rshd not invoke shell options or allow them specified.

the workaround in default debian bashrc skeleton put following @ top of .bashrc:

# if not running interactively, don't [ -z "$ps1" ] && return 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -