Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multi-line variable in tcsh

Tags:

csh

tcsh

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

like image 224
eran Avatar asked Sep 05 '11 08:09

eran


People also ask

How do I create a multiline string in bash?

Although Bash has various escape characters, we only need to concern ourselves with \n (new line character). For example, if we have a multiline string in a script, we can use the \n character to create a new line where necessary.


1 Answers

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.)

like image 94
Keith Thompson Avatar answered Oct 01 '22 11:10

Keith Thompson