setting csh variable to NL (summary)

setting csh variable to NL (summary)

Post by Dujardin INRIA ROCQUENCOU » Tue, 29 Oct 1991 22:10:48

I asked a question some time ago, about setting a csh variable to NL or
any special character. I got some answers, which greatly helped me come to
the following conclusions. I'm using SunOS 4.1.1 .

In fact, I had two problems: the first was to put a special character into
the variable, and the second one was to get the character from it.

1. How to put what I want into this $var

People used to SysV would think of
        set var=`echo \ooo`   (o=octal digit)
but the BSD echo doesn't recognize this syntax.

Hopefully I can do :
        set var=`/usr/5bin/echo \\ooo`
One can also use tr (full BSD-compatible this time):
        set var=`echo A | tr A \\ooo`

But the easiest, by far, is:
        set var=^V^<char> e.g.   set var=^V^H for a backspace
For tabs, you have to enclose the whole into single quotes:
        set var="^V^I"  (i.e., type ctrl-V then ctrl-I or TAB)
(here the ^V is necessary only when using tcsh, with which it means 'file

And for newlines, simply put:
        set nl="\
This way, you don't use external commands.

2. How to use these characters

Let's try echo:
        % set var = "^F"
        % echo -n $var | od -x
        0000000  0600

It works, but when you want to display a $nl...
        set nl="\
        % echo -n $nl | od -x
(same result with a TAB)

Well, the trick is to use the :q modifier
        %echo ab${nl:q}de

That'all !


 INRIA Rocquencourt, projet Sabre
 "Noel au balcon, Paques aux tisons"


1. setting csh variable to NL

Is there a way to put special characters (ie, ascii<32) in csh variables ?
I need this to have several lines in the same variable. I'm using SunOS 4.0.3.

Thanks for any help !

(please answer via Email, I'll post a summary)

 INRIA Rocquencourt, projet Sabre
 "Noel au balcon, Paques aux tisons"

2. How to Dial ISP from user account?

3. Setting variables with variables (sh/bash) [Summary]

4. NFS tuneable paramter?

5. Summary: set ksh variable by C program

6. Linux networking with Novell Client32

7. Q : Set of variables in Csh

8. Script Help: If else statement

9. set environment variable in csh

10. Set variable problem in csh

11. Setting variables in a variable array of null variables

12. question about csh variables defined by "set"

13. Setting DISPLAY variable automatically in CSH