multi-line variable in tcsh

China☆狼群 提交于 2019-12-01 06:04:04
set help = 'my_script\
  -h : -help\
  -b : do boo'

echo $help:q

Another approach:

alias help 'echo "my_script" ; echo "  -h : -help" ; echo "  -b : do boo"'

help

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:

help() {
    cat <<EOF
my_script
  -h : -help
  -b : do boo
EOF
}

help

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:

#!/bin/tcsh

set help =      "my_script   \n" 
set help = "$help  -h : -help\n"
set help = "$help  -b : do boo"

echo $help:q
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!