首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >‘`tcsh`’与subshell重复

‘`tcsh`’与subshell重复
EN

Unix & Linux用户
提问于 2016-04-13 20:46:13
回答 4查看 1.7K关注 0票数 0

我正在努力弄清楚如何在tcsh中重复一个复杂的命令,如下所示

代码语言:javascript
复制
repeat 9999 (curl http://localhost:80/index.php; echo)

这里我使用的是子subshell,而不是{},因为根据http://hyperpolyglot.org/unix-shells,tcsh没有这个特性。

但是,我从前面的构造中得到了以下意外错误。

代码语言:javascript
复制
Badly placed ()'s

那么,如何用tcsh重复一个复杂的命令呢?

关于cshtcsh的奇怪的不一致,有一些老生常谈,比如这个http://www.grymoire.com/unix/CshTop10.txt。所以我不知道该如何看待这个错误。

EN

回答 4

Unix & Linux用户

回答已采纳

发布于 2016-04-13 21:09:20

来自tcsh(1)

代码语言:javascript
复制
repeat count command
    The  specified  command,  which is subject to the same restric‐
    tions as the command in the one line  if  statement  above,  is
    executed  count  times. [..]

并且来自if文档:

代码语言:javascript
复制
if (expr) command
    [..]
    command must  be  a  simple  command,  not  an alias,  a  pipeline,  a
    command list or a parenthesized command list, but it  may  have
    arguments. [..]

看来这不是你能做的事。

要解决这个问题,您可以使用一个简单的包装脚本。

票数 2
EN

Unix & Linux用户

发布于 2017-04-25 15:15:30

我认为你可以用"eval“来表示,例如:

代码语言:javascript
复制
repeat 7 eval "cmd1;cmd2"
票数 3
EN

Unix & Linux用户

发布于 2016-04-13 21:09:52

另一个解决办法是使用ZSH。

代码语言:javascript
复制
% repeat 3 (echo hi; echo there)
hi
there
hi
there
hi
there
% 
票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/276300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档