brad@SSD.CSD.HARRIS.COM (Brad Appleton) (08/18/90)
I need to have a C shell variable contain a new-line. Apparently I can do this at the shell-prompt using: % set foo=a"\ "b % echo $foo:q a b but the following does not work: % set foo=a\ b % echo $foo:q a Regardless, I am required to put my variable setting in a file named "tmp" and set the variable using: % eval `cat tmp` where "tmp" contains the command to set the variable foo! Unfortunately, what worked at the shell prompt does not seem to work when I put it in a file and use eval (regardless of whether or not I use backslashes). ??? SO what must I put into "tmp" to get a newline into $foo:q ??? Please dont post solutions that dont use "eval `cat file`"; such solutions will be of no use to me. Please dont tell me not to use csh either; I dont usually but in this particular case it is part of my requirements-spec. To make matters worse, I cant go translating all newlines in "tmp" to something else (and then back again) because there may be other variable settings in "tmp" which may be terminated by a newline (and/or a semicolon). This one is giving me a lot of grief because I was hoping that what works on the command-line would work in "tmp" (which doesnt seem to be the case for my csh anyway). PS - If youre curious, the reason I have to deal with all the above is that I have a program that will be taking input and spitting out C-shell variable settings. The only character I cant seem to preserve from the input is the newline character. advTHANXance ______________________ "And miles to go before I sleep." ______________________ Brad Appleton brad@travis.ssd.csd.harris.com Harris Computer Systems ...!uunet!hcx1!brad Fort Lauderdale, FL USA ~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~
lars@spectrum.CMC.COM (Lars Poulsen) (08/21/90)
In article <728@travis.csd.harris.com> brad@SSD.CSD.HARRIS.COM (Brad Appleton) writes: >I need to have a C shell variable contain a new-line. >??? SO what must I put into "tmp" to get a newline into $foo:q ??? > >Please dont post solutions that dont use "eval `cat file`"; such >solutions will be of no use to me. Together, let's RTFM: > CSH(1) USER COMMANDS CSH(1) > > Command Substitution > A command enclosed by backquotes (`...`) is performed by a > subshell. Its standard output is broken into separate words > at each SPACE character, TAB and NEWLINE; null words are > discarded. This text replaces the backquoted string on the > current command line. Within double-quotes, only NEWLINE > characters force new words; SPACE and TAB characters are > preserved. However, a final NEWLINE is ignored. It is > therefore possible for a command substitution to yield a > partial word. In other words, it is impossible to have a newline come out of a backquote substitution, because it will be turned into a space. -- / Lars Poulsen, SMTS Software Engineer CMC Rockwell lars@CMC.COM
peter@ficc.ferranti.com (peter da silva) (08/21/90)
You probably have good reasons for doing it that way, but... In article <728@travis.csd.harris.com>, brad@SSD.CSD.HARRIS.COM (Brad Appleton) writes: > Regardless, I am required to put my variable setting in a file named "tmp" > and set the variable using: > % eval `cat tmp` Might I as what is wrong with "source tmp"? As for the quoting, I have found that: set variable "text \ text" (yes, with a *space* before the backslash) works. (As has been noted, CSH is flakier than a bowl of cereal) -- Peter da Silva. `-_-' +1 713 274 5180. 'U` peter@ferranti.com (currently not working) peter@hackercorp.com