9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] rc and spaces in file names
@ 2013-12-20 14:44 trebol
  2013-12-20 15:01 ` erik quanstrom
  0 siblings, 1 reply; 5+ messages in thread
From: trebol @ 2013-12-20 14:44 UTC (permalink / raw)
  To: 9fans

Ok, thanks to both.  I got confused with this part of rc(1):

`{command}
               rc executes the command and reads its standard output,
               splitting it into a list of arguments, using characters
               in $ifs as separators.  If $ifs is not otherwise set,
               its value is ' \t\n'.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] rc and spaces in file names
  2013-12-20 14:44 [9fans] rc and spaces in file names trebol
@ 2013-12-20 15:01 ` erik quanstrom
  0 siblings, 0 replies; 5+ messages in thread
From: erik quanstrom @ 2013-12-20 15:01 UTC (permalink / raw)
  To: 9fans

On Fri Dec 20 09:48:29 EST 2013, trebol55555@aol.com wrote:
> Ok, thanks to both.  I got confused with this part of rc(1):
>
> `{command}
>                rc executes the command and reads its standard output,
>                splitting it into a list of arguments, using characters
>                in $ifs as separators.  If $ifs is not otherwise set,
>                its value is ' \t\n'.

that's a good point.  it looks like the wrong conventions were applied
to that string.  ironically, one would guess, this was to solve a
readability problem.  perhaps "... otherwise set, space, newline, tab will
be used as separators" would be more precice even if it doesn't read
as well.

- erik



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] rc and spaces in file names
  2013-12-20 14:14 trebol
  2013-12-20 14:25 ` erik quanstrom
@ 2013-12-20 14:25 ` Tristan
  1 sibling, 0 replies; 5+ messages in thread
From: Tristan @ 2013-12-20 14:25 UTC (permalink / raw)
  To: 9fans

> term% ifs='\n' for(i in Plan*){cp $i `{echo $i | sed 's/lan/LAN/'}}
> cp: can't create PLAN 9
> : bad character in file name: 'PLAN 9
> '
> cp: can't create PLAN B
> : bad character in file name: 'PLAN B
> '
> '

> So the last newline character is added to the file name...

> I tried typing a literal newline in the ifs variable and it works:

> term% ifs='
> ' for(i in Plan*){cp $i `{echo $i | sed 's/lan/LAN/'}}
> term% ls P*
> 'PLAN 9'
> 'PLAN B'
> 'Plan 9'
> 'Plan B'

> With p9p is the same.  I'll appreciate If anyone can tell me why.

rc doesn't do backslash escapes.

tristan

-- 
All original matter is hereby placed immediately under the public domain.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] rc and spaces in file names
  2013-12-20 14:14 trebol
@ 2013-12-20 14:25 ` erik quanstrom
  2013-12-20 14:25 ` Tristan
  1 sibling, 0 replies; 5+ messages in thread
From: erik quanstrom @ 2013-12-20 14:25 UTC (permalink / raw)
  To: 9fans

> I tried typing a literal newline in the ifs variable and it works:
>
> term% ifs='
> ' for(i in Plan*){cp $i `{echo $i | sed 's/lan/LAN/'}}
> term% ls P*
> 'PLAN 9'
> 'PLAN B'
> 'Plan 9'
> 'Plan B'
>
> With p9p is the same.  I'll appreciate If anyone can tell me why.
>

i'm not sure which question you have.  i'll try to answer the two i see.
'\n' doesn't work because rc doesn't interpret \ except as the last character
of a line.  plan 9 ls helpfully quotes file names that might need quoting
if fed to rc.  ls -Q will get rid of the quotes. (see ls(1).)  so the file names
do not include the single quotes.  if they did, you'd see '''Plan B'''.

- erik



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [9fans] rc and spaces in file names
@ 2013-12-20 14:14 trebol
  2013-12-20 14:25 ` erik quanstrom
  2013-12-20 14:25 ` Tristan
  0 siblings, 2 replies; 5+ messages in thread
From: trebol @ 2013-12-20 14:14 UTC (permalink / raw)
  To: 9fans

Hello,
I usually edit file names with a 'for' statement, so i can replace
spaces and other problematic characters without effort.  But today
I needed to change names keeping spaces and I found something weird.
Let be two files: 'Plan 9' and 'Plan B'.  In a korn or bourne shell I
can do something like:

	$ for i in Plan*; do a=`echo $i | 9 sed s'/lan/LAN/g'`; cp "$i" "$a"; done
without problems with spaces.  In Plan9 I've tried

term% ifs='\n' for(i in Plan*){cp $i `{echo $i | sed 's/lan/LAN/'}}
cp: can't create PLAN 9
: bad character in file name: 'PLAN 9
'
cp: can't create PLAN B
: bad character in file name: 'PLAN B
'
'

So the last newline character is added to the file name...

I tried typing a literal newline in the ifs variable and it works:

term% ifs='
' for(i in Plan*){cp $i `{echo $i | sed 's/lan/LAN/'}}
term% ls P*
'PLAN 9'
'PLAN B'
'Plan 9'
'Plan B'

With p9p is the same.  I'll appreciate If anyone can tell me why.

trebol.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-12-20 15:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-20 14:44 [9fans] rc and spaces in file names trebol
2013-12-20 15:01 ` erik quanstrom
  -- strict thread matches above, loose matches on Subject: below --
2013-12-20 14:14 trebol
2013-12-20 14:25 ` erik quanstrom
2013-12-20 14:25 ` Tristan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).