[comp.unix.questions] Spaces Between Words in Files

abar@cbnewsk.att.com (jerome.t.abar..jr) (11/17/90)

I've run across this problem twice now and nobody here seems to
know what causes it.  I use unix 3.1.5 on a CTRM emulator, but
I've also met people with the same problem who use regular 5425
terminals.

The problem is a file that has two words with a space between
them, such as "foo bar".  How does a file like this get created,
and how do you read it?

I've found that I can erase the file by using rn f*, but it doesn't
work when I try cat f*.  I asked my local help desk expert about it
and she says that people can create those files by accident in a
few different ways but she didn't elaborate.  She also told me that
it wasn't in the manual.  She said that there might be an answer in
VSH but she wasn't sure since she didn't use vsh and didn't know
much about it.

I tried to create a file in vi using two words but I couldn't do it.
I do get a multi-word file created when I run vn instead of rn, but
I can't run the file (it shows up in my home directory).

I'm basically a curious beginner self-taught and learn different
commands as I find a need to know them.  I have no formal unix
training.  Any push in the right direction would be appreciated.
 
Tom Abar

-- 
********************************************************************************** Tom Abar                            My Company's Nifty, My Company's Fine, **** abar@cbnewsk.att.com                But These Opinions Are Strictly MINE!! ********************************************************************************** 

dce@smsc.sony.com (David Elliott) (11/17/90)

In article <1990Nov16.200510.22830@cbnewsk.att.com> abar@cbnewsk.att.com (jerome.t.abar..jr) writes:
>The problem is a file that has two words with a space between
>them, such as "foo bar".  How does a file like this get created,
>and how do you read it?

The only hard part is getting a shell to pass the name through.
Standard shells (derived from sh and csh) allow you to do this
by putting quotes around the name.  So, I can create a file called
"foo bar" by saying

	vi "foo bar"

Single quotes ('') will also work, as will just escaping the space,
as in

	vi foo\ bar

>I've found that I can erase the file by using rn f*, but it doesn't
>work when I try cat f*.

All I can think of is that your version of cat isn't a program, but
an incorrectly-written alias, function, or shell script.

A correctly-written piece of shell code will always assume the
worst about what data the user gives it, and will use some form
of quoting.  For example:

	for i in "$@"
	{
		process_file "$i"
	}

will work fine no matter what the arguments contain. (Yes, I am
assuming a modern shell where "$@" works correctly.)

gwyn@smoke.brl.mil (Doug Gwyn) (11/17/90)

In article <1990Nov16.200510.22830@cbnewsk.att.com> abar@cbnewsk.att.com (jerome.t.abar..jr) writes:
>The problem is a file that has two words with a space between
>them, such as "foo bar".  How does a file like this get created,
>and how do you read it?

You just do it.  If you're using a shell that parses the command
line into words split at occurrences of white space, you have to
somehow quote the space in the filename to keep the shell from
dividing it into two arguments:
	cat 'foo bar'

>... it doesn't work when I try cat f*.

It ought to.  The shell is supposed to expand the pattern f* into
a series of arguments, but not further parse the arguments.