带有非法变量名的Csh问题 [英] Csh issue with Illegal variable name

查看:444
本文介绍了带有非法变量名的Csh问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这就是我的全部代码,我有一个新的错误:变量名称非法。

Ok that's my whole code I have a new Error: Illegal variable name.

当我使用以下命令执行文件时:csh filename.sh

When I execute the file with: csh filename.sh

结果是:非法变量名。

我认为该问题包含在以下部分中:while($?== 1)#!/ bin / sh

I think that the problem containing in the part of: while ( $? == 1 ) #!/bin/sh

set quitter = "N"
# Boucle sur  la condition d'arret du script:
while ( $quitter == "N" )

 # Saisie du nom de l'utilisateur :
 echo "Quel utilisateur ?"
 set a = $<
 # Mettre le résultat de la commande ps -u 
 # dans un fichier quelque soit le résultat (juste ou faux) :
 ps -u $a >&fichier
 # La varible $? vaudra 1 si la dernière commande qui a été éxcuter 
 # a retourné une erreur, 0 sinon.
 # On boucle donc j'usqu'a ce que le nom d'utilisateur soit correct:
 while ( $? == 1 )

   echo -n "Nom d'utilisateur innexistant, entrez un autre :"
   set a = $<
   ps -u $a >&fichier

commande=$(tail -$i tempfile|head -1|cut -d" " -f2)
let i=i+1
echo -n " $commande : "
case $etat
in
D) echo "endormi => ininterruptible" 
S) echo "endormi" 
R) echo "en cours" 
T) echo "stoppe" 
Z) echo "zombi" 
*) echo "inconnu" 
esac
end
 # Suppression du fichier qui a servi aux tests
 rm fichier;
 echo -n "voulez-vous quitter ? (O/N):";set quitter = $<
end


推荐答案

您的代码似乎是bash和csh的混合,并且通过最初的打开(shebang),您有#!/ bin / sh ,这绝对不是csh,并且与旧版本一样含糊不清-行sh = originaUnix * Bourne * Shell或为了方便起见,Linux系统可能以/ bin / sh链接到/ bin / bash。

Your code seems to be a mix of bash and csh AND by your initial opening (the shebang), you have #!/bin/sh, which is definitely not csh, and is ambiguous as the old-line sh=originaUnix*Bourne*Shell OR a linux system may have a link to /bin/bash as /bin/sh for convenience sake.

错误消息告诉您正确的事情, $?不是csh中的有效变量,您想要使用等效的 $ status

The error message is telling your the right thing, $? is not a valid variable in csh, you want to use the equivalent $status.

我无权使用csh来运行您的代码,但是我看到一些问题,一些我知道的csh语法是错误的。

I don't have access to a csh to run your code, but I see several things I question and some I know are wrong for csh syntax.

commande=$(tail -$i tempfile|head -1|cut -d" " -f2)

不起作用,尝试

set commande = `tail -$i tempfile|head -1|cut -d" " -f2`
# tnx to @dwalter for correct syntax on that!

csh case sytnax是

csh case sytnax is

 switch ( "$etat" )
      case D:
        echo "endormi => ininterruptible" 
      breaksw
     default:   
         echo "unknown option provided in as etat=$etat"
     breaksw
  endswitch

,我对此持怀疑态度。

and, I'm skeptical about

ps -u $a >&fichier

您的意图是什么?如果您正在写入文件 fichier ,则看不到您从其中读取的内容。

What is your intent there? If you're writing to the file fichier, I don't see where you're reading from it. What purpose does it serve?

如果您需要进一步的帮助,请编辑问题以包含确切的错误消息(格式为代码)。

If you need further help with this, please edit your question to include the exact error message (formatted as code).

PS

如果将来需要使用Unix脚本,则可以通过放弃使用csh来提高整体可销售性并转换为ksh / bash。由于大部分代码是 bash ,因此最好将第一行更改为#!/ bin / bash 然后研究并修复由此产生的错误消息。

If you require to use Unix scripting in the future, you're overall marketability will be enhanced by dropping use of csh and converting to ksh/bash. As much of the code is bash, you'd be better served changing the first line to #!/bin/bash and then researching and fixing the resulting error messages.

IHTH

这篇关于带有非法变量名的Csh问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆