如何在新的tcsh
交互式 shell 中执行预命令?
例如:为了模仿tcsh
中的bash -O globstar
我们可以做set globstar
但是,tcsh -c 'set globstar'
不起作用,因为它不会离开交互式外壳。执行命令后立即退出。
我需要它在远程计算机上运行脚本,在那里我无法修改任何rc
文件
假设脚本如下
0 > cat run
echo foo/**
有了bash
我可以执行以下操作
0 > bash -O globstar run
foo/ foo/bar foo/bar/foo foo/bar/foo/bar
我正在寻找一个tcsh
等价物,如下所示(它显然不起作用,因为tcsh
不会运行我的程序(
0 > tcsh -c 'set globstar' run
PS:我知道bash -c
和tcsh -c
一样。我正在寻找相当于bash -O
,即使它是有限的选择。
PS:这只是以下问题的tcsh
版本。
在新外壳中运行 bash 命令,并在执行此命令后留在新外壳中
如果您正在运行脚本,则可以通过简单地添加set option
来设置任何选项,就像在启动文件中一样:
#!/usr/bin/env tcsh
set globstar
# .. your code ..
对于 Makefile,同样的事情也应该有效:
SHELL=/bin/tcsh
all:
set noglobstar
set
除此之外,除了更改启动文件之外,没有简单的方法可以做到这一点。据我在手册页中找到,没有开关可以在启动时设置选项,不幸的是,tcsh 也不允许使用命令行参数更改启动文件位置。
为避免更改单个用户的启动文件,您可以将更改放在系统范围的/etc/csh.cshrc
中。从tcsh(1)
:
Startup and shutdown
A login shell begins by executing commands from the system files
/etc/csh.cshrc and /etc/csh.login. It then executes commands from
files in the user's home directory: first ~/.tcshrc (+) or, if
~/.tcshrc is not found, ~/.cshrc, then the contents of ~/.history (or
the value of the histfile shell variable) are loaded into memory, then
~/.login, and finally ~/.cshdirs (or the value of the dirsfile shell
variable) (+). The shell may read /etc/csh.login before instead of
after /etc/csh.cshrc, and ~/.login before instead of after ~/.tcshrc or
~/.cshrc and ~/.history, if so compiled; see the version shell vari‐
able. (+)
Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on
startup.