linux - 在新的交互式 tcsh shell 中执行命令

标签 linux shell tcsh

如何在新的 tcsh 交互式 shell 中执行预命令?

例如:为了在 tcsh 中模仿 bash -O globstar,我们可以执行 set globstar

但是,tcsh -c 'set globstar' 不会工作,因为它不会离开交互式 shell。执行命令后立即退出。

我需要它在我不能修改任何 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 -ctcsh -c 相同。我正在寻找 bash -O 的等价物,即使它的选项有限。

PS:这只是以下问题的 tcsh 版本。

run bash command in new shell and stay in new shell after this command executes

最佳答案

如果您正在运行脚本,您可以通过简单地添加 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.

关于linux - 在新的交互式 tcsh shell 中执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52456389/

相关文章:

linux - Bash 脚本 : Find all filetypes and paths

c++ - stderr 和 stdout 的行为不同

linux - 如何让 ecryptfs 自动使用我的 key ?

linux - aws firecracker 如何处理 vcpu?

java - ssl_client : raw. githubusercontent.com:证书验证失败:自签名证书

shell - 为 shell 脚本指定命令行参数,如名称=值对

Linux jobs命令——如何查看正在运行进程的完整路径

shell - 如何将文件的行按从末尾开始的第二个单词排序

linux - 如何使用linux的convert命令转换图片格式?

linux - shell ||将元素添加到由行而不是空格分隔的数组