在tcsh中找不到命令

问题描述

我在使用此代码时遇到麻烦。我的作业分配正确吗?我给了“ q:找不到命令。严重放置()的。”

#!/bin/tcsh 

set h = 0
set q = 0
set a = 0

foreach val ( $* )
  if ($val == "-h")then
    h = 1
  endif
  if ($val == "-q")then
    q = 1
  endif
  if ($val != "-h") && ($val != "-q")then
    a = 1
  endif
end

解决方法

在有关()和空格的注释的基础上,此版本有效:

#!/bin/tcsh 

set h = 0
set q = 0
set a = 0

foreach val ( $* )
  if ($val == "-h") then
    set h = 1
  endif
  if ($val == "-q") then
    set q = 1
  endif
  if ($val != "-h" && $val != "-q") then
    set a = 1
  endif
end
  1. )之后添加空格
  2. &&放入()
  3. 使用set设置变量。 Bourne shell仅具有x=y,但是* csh需要set x=y

您可能还想研究getopt -如果您有该命令的Linux或GNU版本可用,它可以使选项解析更加标准化。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...