0

I am trying to set variables with string, and construct a more complex string by nesting them. For readibility purpose, I have these strings on multiple lines using \ characters. When I try to do this without the \ it seems to work, but I can't have something working with it.

Example of not working code :

set String_A = "Make \
Something \
End"

set String_B = "${String_A} \
And add \
Something else"

set String_C = "${String_B} Finally something good"

Example of working but unclear code :

set String_A = "Pretty long and unreadable"

set String_B = "${String_A} And add Something else"

set String_C = "${String_B} Finally something"

Could you find a solution where I meet my two requirements ? (Readability on multi lines, and nested strings using variables ?)

Have a good day, Julien

  • 1
    Does this answer your question? [multi-line variable in tcsh](https://stackoverflow.com/questions/7305742/multi-line-variable-in-tcsh) – Dean Van Greunen Aug 31 '23 at 12:51

1 Answers1

0

use single quotes and no space before the slash

set String_A = 'Make\
Something\
End'

set String_B = '${String_A}\
And add\
Something else'

set String_C = '${String_B} Finally something good'

echo $help:q
Dean Van Greunen
  • 5,060
  • 2
  • 14
  • 28
  • 1
    Thank you for your answer. It seems to work effectively if I use only 'something' string nested together. In my script I have quite a lot of other strings that I would like to avoid editing, that are set using double quotes ("). I get an error {Unmatched ".} if I try to mix these two types of string. If I want to mix those two types of string is it possible ? – Julien6405 Aug 31 '23 at 13:07
  • 1
    In other words, what is the fundamental difference between ' and " for strings in csh ? – Julien6405 Aug 31 '23 at 14:58
  • 2
    Also with your method, ${String_A} seems to not be replace by the value of the variable, but stays like an actual string. So it doesn't solve my issue – Julien6405 Aug 31 '23 at 15:05
  • 1
    Yes, output is `${String_A} and add someting else` (over 3 lines. – shellter Aug 31 '23 at 15:06
  • 1
    Try the `var = \`cat\` << EOS .... EOS` version mentioned elsewhere in that answer. Good luck to all. – shellter Aug 31 '23 at 15:07