Bash – how to set globstar for noninteractive shells

bashsshwildcards

I would like to execute commands noninteractively on a remote server that use the ** globstar option. However, globstar is not set by default on the remote, and bash doesn't source any files in noninteractive mode, so I can't add this option to ~/.profile.

Suppose on the remote server

$ shopt -s globstar
$ mkdir -p a/b/c
$ ls a/**
a/:
b

a/b:
c

but remotely,

$ ssh user@remote "ls a**"
a/:
b

How can I enable globstar, ideally by changing the configuration on the remote machine?

Best Answer

If the remote user is using bash then $HOME/.bashrc should be loaded, even in non-interactive shells. You can put your options there.

e.g.

$ head -1 .bashrc 
echo BASHRC loaded

$ ssh localhost echo hello
sweh@localhost's password: 
BASHRC loaded
hello

$