Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Linux

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-13-2008, 08:19 PM
heavytull
 
Posts: n/a
manage blankspaces in filenames

#pwd
/home/user/My Slack Packs/source
#ls
test.tar.gz
#CWD=pwd
#echo $CWD
/home/user/My Slack Packs/source

#tar xzf $CWD/test.tar.gz
tar: /home/user/My: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: Slack: Not found in archive
tar: Packs/test.tar.gz: Not found in archive
tar: Error exit delayed from previous errors

Is there a solution to use tar with variables containing filenames with
blankspaces?

Reply With Quote
  #2 (permalink)  
Old 07-13-2008, 08:42 PM
Chris F.A. Johnson
 
Posts: n/a
Re: manage blankspaces in filenames

On 2008-07-13, heavytull wrote:
> #pwd
> /home/user/My Slack Packs/source
> #ls
> test.tar.gz
> #CWD=pwd
> #echo $CWD
> /home/user/My Slack Packs/source


The result of those last two commands would be:

#CWD=pwd
#echo $CWD
pwd

The current directory is kept in the variable $PWD.

> #tar xzf $CWD/test.tar.gz
> tar: /home/user/My: Cannot open: No such file or directory
> tar: Error is not recoverable: exiting now
> tar: Child returned status 2
> tar: Slack: Not found in archive
> tar: Packs/test.tar.gz: Not found in archive
> tar: Error exit delayed from previous errors
>
> Is there a solution to use tar with variables containing filenames with
> blankspaces?


tar xzf "$PWD/test.tar.gz"


--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
Reply With Quote
  #3 (permalink)  
Old 07-14-2008, 01:10 AM
Unruh
 
Posts: n/a
Re: manage blankspaces in filenames

heavytull <heavytull@hotmail.com> writes:

>#pwd
>/home/user/My Slack Packs/source
>#ls
>test.tar.gz
>#CWD=pwd
>#echo $CWD
>/home/user/My Slack Packs/source


>#tar xzf $CWD/test.tar.gz
>tar: /home/user/My: Cannot open: No such file or directory
>tar: Error is not recoverable: exiting now
>tar: Child returned status 2
>tar: Slack: Not found in archive
>tar: Packs/test.tar.gz: Not found in archive
>tar: Error exit delayed from previous errors


>Is there a solution to use tar with variables containing filenames with
>blankspaces?


A) Bad idea.
B) Since you in /home/user/My Slack Packs/source why not just do
tar xzf test.tar.gz
C) Try tar xzf "$CWD/test.tar.gz"
d) It is a very bad idea to use filenames which spaces. Why are you doing
so?


Reply With Quote
  #4 (permalink)  
Old 07-16-2008, 12:24 AM
Roy Strachan
 
Posts: n/a
Re: manage blankspaces in filenames

On 13 Jul 2008 20:19:19 GMT, heavytull <heavytull@hotmail.com> wrote:

>#pwd
>/home/user/My Slack Packs/source
>#ls
>test.tar.gz
>#CWD=pwd
>#echo $CWD
>/home/user/My Slack Packs/source
>
>#tar xzf $CWD/test.tar.gz
>tar: /home/user/My: Cannot open: No such file or directory
>tar: Error is not recoverable: exiting now
>tar: Child returned status 2
>tar: Slack: Not found in archive
>tar: Packs/test.tar.gz: Not found in archive
>tar: Error exit delayed from previous errors
>
>Is there a solution to use tar with variables containing filenames with
>blankspaces?


use a back slash before the space -
/home/user/My\ Slack\ Packs/source

this escape character works for any character that gets confused on the command
line. (not just spaces)


Reply With Quote
  #5 (permalink)  
Old 07-18-2008, 06:38 PM
Florian Diesch
 
Posts: n/a
Re: manage blankspaces in filenames

Unruh <unruh-spam@physics.ubc.ca> wrote:


> d) It is a very bad idea to use filenames which spaces.


No, there's nothing wrong with using spaces in file names. It's a very
bad idea to assume that file names don't contain white spaces.



Florian
--
<http://www.florian-diesch.de/>
-----------------------------------------------------------------------
** Hi! I'm a signature virus! Copy me into your signature, please! **
-----------------------------------------------------------------------
Reply With Quote
  #6 (permalink)  
Old 07-19-2008, 03:44 PM
Unruh
 
Posts: n/a
Re: manage blankspaces in filenames

Florian Diesch <diesch@spamfence.net> writes:

>Unruh <unruh-spam@physics.ubc.ca> wrote:



>> d) It is a very bad idea to use filenames which spaces.


>No, there's nothing wrong with using spaces in file names. It's a very
>bad idea to assume that file names don't contain white spaces.


As you know, a space has a special meaning to the shell-- it is the "word
delimiter" to use something which means something spacial like that in the
filename is simply asking for trouble. Would you also put single quotes
into a file name, or backspaces, or semicolonsi or backslashes, all of which have special
meanings? While there are ways of getting around it, it is just plain
idiotic to use those things in filenames.


> Florian
>--
><http://www.florian-diesch.de/>
>-----------------------------------------------------------------------
>** Hi! I'm a signature virus! Copy me into your signature, please! **
>-----------------------------------------------------------------------

Reply With Quote
  #7 (permalink)  
Old 07-19-2008, 04:50 PM
J.O. Aho
 
Posts: n/a
Re: manage blankspaces in filenames

Unruh wrote:
> Florian Diesch <diesch@spamfence.net> writes:
>
>> Unruh <unruh-spam@physics.ubc.ca> wrote:

>
>
>>> d) It is a very bad idea to use filenames which spaces.

>
>> No, there's nothing wrong with using spaces in file names. It's a very
>> bad idea to assume that file names don't contain white spaces.

>
> As you know, a space has a special meaning to the shell-- it is the "word
> delimiter" to use something which means something spacial like that in the
> filename is simply asking for trouble. Would you also put single quotes
> into a file name, or backspaces, or semicolonsi or backslashes, all of which have special
> meanings? While there are ways of getting around it, it is just plain
> idiotic to use those things in filenames.


There is nothing wrong in using spaces in file names, it's just anoying, but
as people eare used to use spaces in the file names from microsoft, so it's
better to use quotes around file names, this way it will work regardless if
there is spaces or not.

Chris did point this out in the first reply.

--

//Aho
Reply With Quote
  #8 (permalink)  
Old 07-19-2008, 05:17 PM
Florian Diesch
 
Posts: n/a
Re: manage blankspaces in filenames

Unruh <unruh-spam@physics.ubc.ca> wrote:

> Florian Diesch <diesch@spamfence.net> writes:
>
>>Unruh <unruh-spam@physics.ubc.ca> wrote:

>
>>> d) It is a very bad idea to use filenames which spaces.

>
>>No, there's nothing wrong with using spaces in file names. It's a very
>>bad idea to assume that file names don't contain white spaces.

>
> As you know, a space has a special meaning to the shell-- it is the "word
> delimiter" to use something which means something spacial like that in the
> filename is simply asking for trouble.


No. With some basic shell knowledge that's no problem.

> Would you also put single quotes
> into a file name, or backspaces, or semicolonsi or backslashes, all of which have special
> meanings?


Backspace isn't printable so it usually doesn't make much sense to
use it in filenames. The other characters are fine.

diesch@scenic:~% locate \ |wc
6462 34949 445299
diesch@scenic:~% locate \;|wc
26 36 2001
diesch@scenic:~% locate \'|wc
5741 9488 336916
diesch@scenic:~% locate \`|wc
70 79 3377
diesch@scenic:~% locate \"|wc
41 446 4427
diesch@scenic:~% locate \\|wc
0 0 0


> While there are ways of getting around it, it is just plain
> idiotic to use those things in filenames.


The Ubuntu maintainers don't see any problem with spaces in
filenames, too:

diesch@scenic:~% locate \ |grep -v home|wc
112 289 7622


Florian
--
<http://www.florian-diesch.de/>
-----------------------------------------------------------------------
** Hi! I'm a signature virus! Copy me into your signature, please! **
-----------------------------------------------------------------------
Reply With Quote
  #9 (permalink)  
Old 07-20-2008, 12:01 AM
Unruh
 
Posts: n/a
Re: manage blankspaces in filenames

Florian Diesch <diesch@spamfence.net> writes:

>Unruh <unruh-spam@physics.ubc.ca> wrote:


>> Florian Diesch <diesch@spamfence.net> writes:
>>
>>>Unruh <unruh-spam@physics.ubc.ca> wrote:

>>
>>>> d) It is a very bad idea to use filenames which spaces.

>>
>>>No, there's nothing wrong with using spaces in file names. It's a very
>>>bad idea to assume that file names don't contain white spaces.

>>
>> As you know, a space has a special meaning to the shell-- it is the "word
>> delimiter" to use something which means something spacial like that in the
>> filename is simply asking for trouble.


>No. With some basic shell knowledge that's no problem.


>> Would you also put single quotes
>> into a file name, or backspaces, or semicolonsi or backslashes, all of which have special
>> meanings?


>Backspace isn't printable so it usually doesn't make much sense to
>use it in filenames. The other characters are fine.


>diesch@scenic:~% locate \ |wc
> 6462 34949 445299
>diesch@scenic:~% locate \;|wc
> 26 36 2001
>diesch@scenic:~% locate \'|wc
> 5741 9488 336916
>diesch@scenic:~% locate \`|wc
> 70 79 3377
>diesch@scenic:~% locate \"|wc
> 41 446 4427
>diesch@scenic:~% locate \\|wc
> 0 0 0



>> While there are ways of getting around it, it is just plain
>> idiotic to use those things in filenames.


>The Ubuntu maintainers don't see any problem with spaces in
>filenames, too:


>diesch@scenic:~% locate \ |grep -v home|wc
> 112 289 7622


I maintain my position. It is just plain idiotic to sue those things in
filenames.

Reply With Quote
  #10 (permalink)  
Old 07-20-2008, 05:10 PM
heavytull
 
Posts: n/a
Re: manage blankspaces in filenames

On Sat, 19 Jul 2008 18:50:06 +0200, J.O. Aho wrote:

> There is nothing wrong in using spaces in file names, it's just anoying,
> but as people eare used to use spaces in the file names from microsoft,
> so it's better to use quotes around file names, this way it will work
> regardless if there is spaces or not.
>
> Chris did point this out in the first reply.


that's not because of microsoft that i'm using spaces.

for very long I have never used spaces, i just recently chose to use
blanks, because it looks good and unix filenames accepts the use of it.
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Linux


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:39 AM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109