如何为非交互式 shell 设置 globstar

pet*_*arp 3 bash ssh wildcards

我想在使用** globstar 选项的远程服务器上以非交互方式执行命令。但是,默认情况下,遥控器上未设置 globstar,并且bash 不会在非交互模式下获取任何文件,因此我无法将此选项添加到~/.profile.

假设在远程服务器上

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

a/b:
c
Run Code Online (Sandbox Code Playgroud)

但远程,

$ ssh user@remote "ls a**"
a/:
b
Run Code Online (Sandbox Code Playgroud)

理想情况下,如何通过更改远程计算机上的配置来启用 globstar?

Ste*_*ris 7

如果远程用户正在使用,bash$HOME/.bashrc应该加载,即使在非交互式 shell 中也是如此。你可以把你的选择放在那里。

例如

$ head -1 .bashrc 
echo BASHRC loaded

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

$ 
Run Code Online (Sandbox Code Playgroud)

  • 为什么,确实如此。在说“如果不互动就停止”之后,我有“shopt -s globstar”。 (3认同)