shell 中出现未知错误

发布于 2024-09-03 10:42:41 字数 366 浏览 2 评论 0原文

有人可以解释一下这个错误是什么意思吗:

 > ./rank lines.in
'nknown option: `-
Usage: tcsh [ -bcdefilmnqstvVxX ] [ argument ... ].

这是我的脚本等级:

#! /bin/tcsh -f
set line = `cat ${1}`
echo $line

我认为我遇到的问题是第一行#! /bin/tcsh -f 我正在 Windows 上工作!但是当我在 Windows 编辑器上编写脚本后,我使用 dos2unix 等级转换它,这可能是什么问题,提前感谢您的帮助

can somebody explain me what does this error mean:

 > ./rank lines.in
'nknown option: `-
Usage: tcsh [ -bcdefilmnqstvVxX ] [ argument ... ].

this is my script rank:

#! /bin/tcsh -f
set line = `cat ${1}`
echo $line

I think that the problem I have is with first row #! /bin/tcsh -f
I'm working on Windows! but after I wrote script on windows editor, I converted it using dos2unix rank, what can be the problem, thanks in advance for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

┊风居住的梦幻卍 2024-09-10 10:42:41

我认为你的 dos2unix 不起作用。看来您在 hash-bang 行的末尾仍然有一个它不喜欢的 \r 。看起来它看到了 /bin/tcsh -f\r,将其解释为 /bin/tcsh -f -\r,然后尝试打印错误消息:

Unknown option: `-\r'

\r 导致结束引号出现在行的开头。如果您想准确查看文件中的内容,请尝试使用 cat -A ./rank 打印所有隐藏字符。你可能会看到

#! /bin/tcsh -f^M$

I don't think your dos2unix worked. It appears you've still got a \r at the end of the hash-bang line that it doesn't like. It looks like it's seeing /bin/tcsh -f\r, interpreting that as /bin/tcsh -f -\r, and then attempting to print the error message:

Unknown option: `-\r'

The \r is causing the end quote to appear at the beginning of the line. If you want to see exactly what's in your file try cat -A ./rank to print all hidden characters. You'll probably see

#! /bin/tcsh -f^M$
尝蛊 2024-09-10 10:42:41

我将 tcsh 安装到我的 Linux 机器上并运行该脚本并且它起作用了,所以我猜你的换行符是错误的。

该错误似乎只是意味着当调用 tcsh shell 时,它接收到无效参数。我认为它得到的是整个脚本作为参数列表。我尝试将 -f 更改为 -g (不被识别为 tcsh 参数),然后得到:

Unknown option: `-g'
Usage: tcsh [ -bcdefilmnqstvVxX ] [ argument ... ].

注意它如何仍然告诉我无效参数的名称?

要么是你的 tcsh 启动错误。启动 tcsh shell 时可以给出默认参数。您尝试过启动一个吗?

但实际上,学习 tcsh 的唯一原因是您需要维护一些古老的 tcsh 脚本。即使这样,如果可能的话,我也会首先将它们转换为其他脚本语言。如果您想学习 shell 脚本,请尝试 bash 或 bourne shell。 tcsh 会让你生气的原因有很多。

I installed tcsh to my Linux box and run that script and it worked, so I guess your line breaks are wrong.

The error simply seems to mean that when the tcsh shell is called it receives invalid parameters. I think what it gets is the whole script as the parameter list. I tried changing -f to -g (not recognised as a tcsh parameter) and I got:

Unknown option: `-g'
Usage: tcsh [ -bcdefilmnqstvVxX ] [ argument ... ].

Notice how it still tells me the name of the invalid parameter?

Either that or your tcsh starts wrong. It is possible to give default parameters when starting a tcsh shell. Have you tried starting one?

But really, the only reason to learn tcsh would be if you need to maintain some age old tcsh scripts. And even then I would start by converting them to some other scripting language, if at all possible. If you want to learn shell scripting, try bash or bourne shell. There are many reasons why tcsh will just make you mad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文