LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-14-2006, 02:06 PM   #16
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled

Because you need to type:
Code:
cat "$v8"
 
Old 04-14-2006, 03:00 PM   #17
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662

Rep: Reputation: 47
The following is the output:

[nissanka@c83-250-108-126 ~]$ cat "$v8"
cat: The Holy Family's flight to Egypt : No such file or directory
[nissanka@c83-250-108-126 ~]$
 
Old 04-14-2006, 03:21 PM   #18
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,272

Rep: Reputation: 154Reputation: 154
Remember file names are case sensitve, and the file must be in your cwd. This is what happened when I did it:
Code:
$ echo "File Contents" > "The Holy Family's flight to Egypt"
$ v8="The Holy Family's flight to Egypt"
$ cat "$v8"
File Contents
$
 
Old 04-14-2006, 03:31 PM   #19
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662

Rep: Reputation: 47
I didn't write the file name; I just copied and pasted. I know very well about the case sensitivity aspects in Linux.

What shall I write for the words 'File Contents''?

It is a big file. I read it on an online newspaper and saved it. I have no problems to open it using the web browser.

[nissanka@c83-250-108-126 ~]$ pwd
/home/nissanka
[nissanka@c83-250-108-126 ~]$
 
Old 04-14-2006, 04:15 PM   #20
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,272

Rep: Reputation: 154Reputation: 154
Forget the first line, with the echo, that just created a file with the name same as yours with just any arbitary text content to show you how it works.

Something went wrong, cat reckons the file doesn't exist so you either spelt it wrong or that file is not in your home directory. When defining the variable you made sure there was no leading or trailing white space?
 
Old 04-14-2006, 04:15 PM   #21
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
You said
Quote:
I have file called '' The Holy Family's flight to Egypt ''.
You tried
Quote:
[nissanka@c83-250-108-126 ~]$ cat "$v8"
cat: The Holy Family's flight to Egypt : No such file or directory
So I guess you *don't* really have a file called "The Holy Family's flight to Egypt".

Or you do, and it exists in some other directory.

Who cares?

The point is:
1. A Linux file name can contain spaces (maybe unwise, but you can do it)
2. A Linux shell variable can also contain spaces (it's very common)
3. When Linux *EXPANDS* the shell variable, everything delimited by a space is BROKEN INTO A SEPARATE WORD
... But ...
4. You can KEEP your shell-variable-with-spaces as a SINGLE word ... by using quotes (").

That's the beginning and end of all I was trying to say.
 
Old 04-17-2006, 06:35 AM   #22
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
Because "cat $v8" is expanded to "cat The Holy Family's flight to Egypt". the command cat will try to open several files named "The", and "Holy" ....
The correct way to avoid such mistake is protect the cat's argument with a double quote:
Code:
$ cat "$v8"
which expands to 
$ cat "The Holy Family's flight to Egypt "
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ProFTPd installed, but not functioning properly kyletriggs Linux - Software 3 02-20-2006 12:00 PM
My network is not functioning properly procfs Linux - Networking 5 02-16-2006 12:50 AM
TCPIP not functioning properly safescott Linux - Networking 8 06-02-2003 01:13 AM
C++ problem , string.h not functioning properly cyberswami Programming 4 02-18-2003 11:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration