Enforcing spaces in variables (CSH)

Enforcing spaces in variables (CSH)

Post by Chris L » Fri, 04 Jun 1993 04:40:12



Is there a way to have a shell variable track spaces in csh?
For instance, if I set a variable by

     % set hw='hello   world'
     % echo $hw
     hello world

The spaces between hello and world have been condensed into 1 space.

Just curious.  Thanks in advance.
--
Chris Lee
University of Illinois Urbana

(217)244-2903

 
 
 

Enforcing spaces in variables (CSH)

Post by Robert Ea » Fri, 04 Jun 1993 05:23:57


| Is there a way to have a shell variable track spaces in csh?
| For instance, if I set a variable by

|      % set hw='hello   world'
|      % echo $hw
|      hello world

| The spaces between hello and world have been condensed into 1 space.

% echo "$hw"
hello  world

This is just one example of how csh will rescan command lines numerous
times, thus screwing up embedded quoting and spacing.  Real shells get
this right without the surrounding quotes.
--
robert earl           |



 
 
 

Enforcing spaces in variables (CSH)

Post by Lars Joergen A » Fri, 04 Jun 1993 08:07:35


: Is there a way to have a shell variable track spaces in csh?
: For instance, if I set a variable by

:      % set hw='hello   world'
:      % echo $hw
:      hello world

: The spaces between hello and world have been condensed into 1 space.
: Just curious.  Thanks in advance.

Since "echo" is a program like any other tool, you must quote the arguments
that should be only one argument (Anyone wan't to try to explain it better???)
so if you write:  echo "$hw", everything in hw is 1 argument, but if you
write $hw, $hw is expanded and each word becomes an argument each, so
echo just prints each argument with a character from $IFS between...
To see what I mean try:
echo Hello   world
and
echo "Hello   world"

--
Lars J (my sig)

 
 
 

Enforcing spaces in variables (CSH)

Post by Bill Rieme » Mon, 14 Jun 1993 01:31:12


NNTP-Posting-Host: eith.biostr.washington.edu

        Robert> % echo "$hw"
        Robert> hello  world

        Robert> This is just one example of how csh will rescan command lines numerous
        Robert> times, thus screwing up embedded quoting and spacing.  Real shells get
        Robert> this right without the surrounding quotes.

Normally this is an advantage, not a disadvantage!  If you really don't want the
quotes try:

  echo $hw:q

Normally, by rescanning the line, insignificant differences are eliminated.  This
is very helpfull for scripts...  Personally, I consider "csh"'s handling of variables
one of it's major advantage.  With "sh" you end-up calling external programs (slowing
your script down) to do simple things like remove pathnames from filenames, or spaces
from strings.

                                   Bill
--
"Yeti!  Saw them in the London Underground twenty years ago.  Ghosts!
A headless woman used to walk through my bedroom at midnight.  Mermaids?
Grandpa was rescued from the Marie Celeste by one.  Vampires?  I always
wondered where my dad went to at night.  Telepathy?  Right now you're
thinking that I'm talking crap.  So what can you tell me that I won't
believe in?" - Andrew Hunt, "CAT'S CRADLE: WITCH MARK"

 
 
 

1. \ creates a double space in variables (csh)

Hello all,

I've RTFM and I'm still stumped.  I'm trying to write a csh script that
has "string" variables long enough that they need to be on more than
one line.  The problem is that when I use \ to break up the line, it
creates a double space in the variable.  For example:

######################
#! /bin/csh

set myvar = "here comes the \
double space"

echo $myvar
######################

will output "here comes the  double space"

Anyone know how to get rid of that?  Yes I've tried taking out the
space before the \.  Nope, it doesn't work.

Thanks,
- Geoff Graham

Sent via Deja.com http://www.deja.com/
Before you buy.

2. tape drive

3. enforce ftp, deny ssh, enforce ssh, deny ftp

4. no beep under doslinux?

5. Variable depending on other variable. (csh)

6. terminal idle time

7. Variable variable names is csh

8. Couldn't understand the MACRO defn in linux/module.h

9. csh shell, problem with echoing variable variables...

10. prefixing a shell variable with a variable number of spaces

11. Lack of spaces in csh if statements cause nesting to fail.

12. csh scripts and variable evaluation..

13. Use of csh _local_ variables path/term/etc.