tcsh 中的多行变量
我想在 tcsh 中使用变量来保存脚本的使用信息,因此在我的脚本中,每当我编写 echo $usage 时,它都会打印
my_script
-h : -help
-b : do boo
etc`。
有办法做到这一点吗?这可以使用 << 来完成吗? EOF?
我尝试过类似的方法,但失败了:
set help = << EOF
my_script
-h : print help
-b : do boo
EOF
谢谢
I want to have variable in tcsh to hold the usage info of my script, so in my script, whenever I write echo $usage, it will print
my_script
-h : -help
-b : do boo
etc`.
Is there a way to do this? Can this be done using the << EOF ?
I've tried something like this, but it failed:
set help = << EOF
my_script
-h : print help
-b : do boo
EOF
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另一种方法:
但另请参阅:http://www.faqs.org /faqs/unix-faq/shell/csh-whynot/
我使用 csh 和 tcsh 的时间比我愿意承认的要长,但我不得不通过反复试验来找出第一个 解决方案。例如,
echo "$help"
不起作用;我不知道为什么,我怀疑我能否从文档中找出答案。(在 Bourne shell 中,您可以这样做:
但 csh 和 tcsh 没有函数。)
Another approach:
But see also: http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
I've been using csh and tcsh for more years than I care to admit, but I had to resort to trial and error to figure out the first solution. For example,
echo "$help"
doesn't work; I don't know why, and I doubt that I could figure it out from the documentation.(In Bourne shell, you could do it like this:
but csh and tcsh don't have functions.)
使用
''
会停止评估变量,这在您的情况下不是问题,但在其他情况下可能会出现问题。为了使其更具可读性并允许字符串分布在多行中,我使用以下命令:Using
''
stops variables being evaluated, not an issue in your case but can be in other situations. To make it a little more readable and allowing the string to be spread over multiple lines I use the following:你的代码几乎是正确的。但是,您忘记了
cat
:现在您已经设置了,您可以应用一个循环来循环文本:
如果更好,您可以有一个
goto
标签并递归到脚本中:这是一个函数的模拟。
Your code is almost correct. You forgot, however, of
cat
:Now that you have set, you can apply a loop to cycle through the text:
If any better, you can have a
goto
label and recurse into the script:This is a simulation of a function.