Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

All extremists should be taken out and shot.


devel / comp.unix.shell / Re: spaces in file names

SubjectAuthor
* spaces in file namesPopping Mad
+- Re: spaces in file namesMartin Τrautmann
+* Re: spaces in file namesJanis Papanagnou
|+* Re: spaces in file namesJanis Papanagnou
||`* Re: spaces in file namesPopping Mad
|| `* Re: spaces in file namesJanis Papanagnou
||  `* Re: spaces in file namesKenny McCormack
||   `- Re: spaces in file namesJanis Papanagnou
|`* Re: spaces in file namesPopping Mad
| +* Re: spaces in file namesWilliam Unruh
| |`- Re: spaces in file namesPopping Mad
| +* Re: spaces in file namesKaz Kylheku
| |+* Re: spaces in file namesKeith Thompson
| ||`- Re: spaces in file namesJanis Papanagnou
| |`* Re: spaces in file namesPopping Mad
| | +* Re: spaces in file namesWilliam Unruh
| | |`* Re: spaces in file namesPopping Mad
| | | `* Re: spaces in file namesJanis Papanagnou
| | |  `- Re: spaces in file namesEric Pozharski
| | `* Re: spaces in file namesJanis Papanagnou
| |  `- Re: spaces in file namesPopping Mad
| `* Re: spaces in file namesJanis Papanagnou
|  `* Re: spaces in file namesKenny McCormack
|   `- Re: spaces in file namesJanis Papanagnou
+* Re: spaces in file namesEd Morton
|`- Re: spaces in file namesPopping Mad
+* Re: spaces in file namesBen Bacarisse
|+* Re: spaces in file namesPopping Mad
||`- Re: spaces in file namesJanis Papanagnou
|`* Re: spaces in file namesPopping Mad
| `* Re: spaces in file namesJanis Papanagnou
|  +* Re: spaces in file namesBen Bacarisse
|  |`* Re: spaces in file namesJanis Papanagnou
|  | `- Re: spaces in file namesBen Bacarisse
|  `* Re: spaces in file namesKenny McCormack
|   `- Re: spaces in file namesJanis Papanagnou
+* Re: spaces in file namesHelmut Waitzmann
|+* Re: spaces in file namesKaz Kylheku
||+- Re: spaces in file namesJanis Papanagnou
||`- Re: spaces in file namesHelmut Waitzmann
|+* Re: spaces in file namesPopping Mad
||`- Re: spaces in file namesJanis Papanagnou
|`* Re: spaces in file namesPopping Mad
| `- Why 'for v in `ls ...` ; do ... ; done' won't work: command substitution and fieHelmut Waitzmann
`* Re: spaces in file namesRandal L. Schwartz
 +- Re: spaces in file namesKeith Thompson
 `* Re: spaces in file namesBarry Margolin
  +- Re: spaces in file namesEli the Bearded
  +- Re: spaces in file namesJosef Moellers
  `- Re: spaces in file namesBenjamin Esham

Pages:12
Re: spaces in file names

<sbgbvg$6lh$1@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4000&group=comp.unix.shell#4000

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.www3.mrbrklyn.com!not-for-mail
From: rain...@colition.gov (Popping Mad)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Tue, 29 Jun 2021 19:55:09 -0400
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <sbgbvg$6lh$1@reader1.panix.com>
References: <samjbi$q3a$1@reader1.panix.com>
<san3rs$mri$1@news-1.m-online.net> <satthq$6kj$1@reader2.panix.com>
<20210622174241.378@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 29 Jun 2021 23:56:32 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="www3.mrbrklyn.com:96.57.23.83";
logging-data="6833"; mail-complaints-to="abuse@panix.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
In-Reply-To: <20210622174241.378@kylheku.com>
Content-Language: en-US
 by: Popping Mad - Tue, 29 Jun 2021 23:55 UTC

On 6/22/21 8:46 PM, Kaz Kylheku wrote:
> On 2021-06-22, Popping Mad <rainbow@colition.gov> wrote:
>> On 6/20/21 6:04 AM, Janis Papanagnou wrote:
>>> It's beyond me why folks dismiss a correct and efficient
>>> construct (a simple for-loop file pattern) and want to
>>> replace it by wrong and inefficient constructs (subshell
>>> and ls) - ...and then wonder why the code breaks!
>>
>>
>> well, because it is incoherent. A random ./* in the middle of a shell
>> statement with out an instruction like ls is naked.
>
> There is a bleeping instruction: "for x in"!
>
> for x in ./* ; do ...
>
>
>> flatbush:[ruben]:~$ ./*
>> bash: ./abr2.mp4: Permission denied
>
> Strawman nonsense. Nick checks out?

On 6/22/21 8:46 PM, Kaz Kylheku wrote:
> Nouns ... verbs

subject and ojects

../* is not a command in bash in of itself.

for x in expects a list

this is not a list ./*

`ls ./*`

does produce a list. That is how I think about it. Obviously, I am wrong.

>
>> So there is nothing to be amazed at. It is simple language syntax,
>> nouns and verbs, that one would expect.
>
> Yeah, simple language.
>
> Nouns ... verbs ... nested backticks with an embedded useless ls ...
>
> You know, natural!
>

Re: spaces in file names

<sbgc6b$6lh$2@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4001&group=comp.unix.shell#4001

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.www3.mrbrklyn.com!not-for-mail
From: rain...@colition.gov (Popping Mad)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Tue, 29 Jun 2021 19:58:52 -0400
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <sbgc6b$6lh$2@reader1.panix.com>
References: <samjbi$q3a$1@reader1.panix.com> <sanhvo$7p6$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 30 Jun 2021 00:00:11 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="www3.mrbrklyn.com:96.57.23.83";
logging-data="6833"; mail-complaints-to="abuse@panix.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
In-Reply-To: <sanhvo$7p6$1@dont-email.me>
Content-Language: en-US
 by: Popping Mad - Tue, 29 Jun 2021 23:58 UTC

On 6/20/21 10:05 AM, Ed Morton wrote:
>> ".mp3
>> done
>>
>> but it broke with each space for song names
>
> Some shell programming fundamentals:
>
> https://mywiki.wooledge.org/DontReadLinesWithFor
> https://mywiki.wooledge.org/BashFAQ/001
> https://mywiki.wooledge.org/ParsingLs
>
>     Ed.

thanks

Re: spaces in file names

<sbgc7p$6lh$3@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4002&group=comp.unix.shell#4002

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.www3.mrbrklyn.com!not-for-mail
From: rain...@colition.gov (Popping Mad)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Tue, 29 Jun 2021 19:59:38 -0400
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <sbgc7p$6lh$3@reader1.panix.com>
References: <samjbi$q3a$1@reader1.panix.com> <87y2b4bog0.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 30 Jun 2021 00:00:57 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="www3.mrbrklyn.com:96.57.23.83";
logging-data="6833"; mail-complaints-to="abuse@panix.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
In-Reply-To: <87y2b4bog0.fsf@bsb.me.uk>
Content-Language: en-US
 by: Popping Mad - Tue, 29 Jun 2021 23:59 UTC

On 6/20/21 10:28 AM, Ben Bacarisse wrote:
> The list that results from the ls command is subject to word splitting.

and not from ./* ?

Re: spaces in file names

<sbgcb8$6lh$4@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4003&group=comp.unix.shell#4003

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.www3.mrbrklyn.com!not-for-mail
From: rain...@colition.gov (Popping Mad)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Tue, 29 Jun 2021 20:01:30 -0400
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <sbgcb8$6lh$4@reader1.panix.com>
References: <samjbi$q3a$1@reader1.panix.com> <87y2b4bog0.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 30 Jun 2021 00:02:48 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="www3.mrbrklyn.com:96.57.23.83";
logging-data="6833"; mail-complaints-to="abuse@panix.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
In-Reply-To: <87y2b4bog0.fsf@bsb.me.uk>
Content-Language: en-US
 by: Popping Mad - Wed, 30 Jun 2021 00:01 UTC

On 6/20/21 10:28 AM, Ben Bacarisse wrote:
> For some reason the author is treating a as an array. This is harmless,
> but unless I'm missing something, it's also pointless. You could write
>
> "${a/%flac/mp3}"
>
> instead. The ${var/s1/s2} syntax gives the value of $var but with the
> first occurrence of s1 replaced by s2. In the % form (${var/%s1/s2}) s1
> must match as the end of $var

Excellent - thanks

Re: spaces in file names

<443a4030-7548-0f27-c154-ec7bb1737b77@colition.gov>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4004&group=comp.unix.shell#4004

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.www3.mrbrklyn.com!not-for-mail
From: rain...@colition.gov (Popping Mad)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Tue, 29 Jun 2021 20:03:41 -0400
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <443a4030-7548-0f27-c154-ec7bb1737b77@colition.gov>
References: <samjbi$q3a$1@reader1.panix.com>
<8335tc4fz1.fsf@helmutwaitzmann.news.arcor.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader1.panix.com; posting-host="www3.mrbrklyn.com:96.57.23.83";
logging-data="6833"; mail-complaints-to="abuse@panix.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
To: "Helmut Waitzmann Anti-Spam-Ticket.b.qc3c" <oe.throttle@xoxy.net>
In-Reply-To: <8335tc4fz1.fsf@helmutwaitzmann.news.arcor.de>
Content-Language: en-US
 by: Popping Mad - Wed, 30 Jun 2021 00:03 UTC

On 6/20/21 1:13 PM, Helmut Waitzmann wrote:
>   for a in `ls ./*.flac`; do
>
> will not work (because of field splitting), neither will
>
>   for a in "`ls ./*.flac`"; do

but why is the default field split a space for the ls execution and not
for ./* ?

Re: spaces in file names

<sbgcfp$6lh$6@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4005&group=comp.unix.shell#4005

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.www3.mrbrklyn.com!not-for-mail
From: rain...@colition.gov (Popping Mad)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Tue, 29 Jun 2021 20:03:55 -0400
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <sbgcfp$6lh$6@reader1.panix.com>
References: <samjbi$q3a$1@reader1.panix.com>
<8335tc4fz1.fsf@helmutwaitzmann.news.arcor.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 30 Jun 2021 00:05:13 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="www3.mrbrklyn.com:96.57.23.83";
logging-data="6833"; mail-complaints-to="abuse@panix.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
In-Reply-To: <8335tc4fz1.fsf@helmutwaitzmann.news.arcor.de>
Content-Language: en-US
 by: Popping Mad - Wed, 30 Jun 2021 00:03 UTC

On 6/20/21 1:13 PM, Helmut Waitzmann wrote:
>   for a in `ls ./*.flac`; do
>
> will not work (because of field splitting), neither will
>
>   for a in "`ls ./*.flac`"; do

but why is the default field split a space for the ls execution and not
for ./* ?

Re: spaces in file names

<sbgvak$b1b$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4006&group=comp.unix.shell#4006

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: unr...@invalid.ca (William Unruh)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 05:26:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <sbgvak$b1b$1@dont-email.me>
References: <samjbi$q3a$1@reader1.panix.com>
<san3rs$mri$1@news-1.m-online.net> <satthq$6kj$1@reader2.panix.com>
<20210622174241.378@kylheku.com> <sbgbvg$6lh$1@reader1.panix.com>
Injection-Date: Wed, 30 Jun 2021 05:26:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9788e235cad293f03b92af20c86029a6";
logging-data="11307"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GAZ8zY3wzYNr6m2HMZEtw"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:IO/ZGM3QJwYgTldgKuO1yt3I7Ns=
 by: William Unruh - Wed, 30 Jun 2021 05:26 UTC

On 2021-06-29, Popping Mad <rainbow@colition.gov> wrote:
>
>
> On 6/22/21 8:46 PM, Kaz Kylheku wrote:
>> Nouns ... verbs
>
> subject and ojects
>
> ./* is not a command in bash in of itself.
>
> for x in expects a list
>
> this is not a list ./*
>
> `ls ./*`

actually
for x in ./*
is a list. The shell expands ./* before it runs the command (for x in)
so that will produce a whole list of items -- all of the filenames that
do not start with . in the current directory.
Try
for i in ./*
do
echo $i
done

>
> does produce a list. That is how I think about it. Obviously, I am wrong.
>
>>

Re: spaces in file names

<sbhdrn$rrr$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4007&group=comp.unix.shell#4007

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 11:34:47 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 35
Message-ID: <sbhdrn$rrr$1@news-1.m-online.net>
References: <samjbi$q3a$1@reader1.panix.com>
<san3rs$mri$1@news-1.m-online.net> <san8k2$o5p$2@news-1.m-online.net>
<sbgbjf$7v3$1@reader1.panix.com>
NNTP-Posting-Host: 2001:a61:241e:cc01:5d6d:3b18:94fd:48be
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1625045687 28539 2001:a61:241e:cc01:5d6d:3b18:94fd:48be (30 Jun 2021 09:34:47 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Wed, 30 Jun 2021 09:34:47 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <sbgbjf$7v3$1@reader1.panix.com>
 by: Janis Papanagnou - Wed, 30 Jun 2021 09:34 UTC

On 30.06.2021 01:48, Popping Mad wrote:
> On 6/20/21 7:25 AM, Janis Papanagnou wrote:
>> Oops..
>>
>> On 20.06.2021 12:04, Janis Papanagnou wrote:
>>>
>>> What you probably just want is basically
>>>
>>> for a in ./*.flac
>>> do
>>> ffmeg ... "$a" ... "${a%flac}.mp3"
>>
>> ffmeg ... "$a" ... "${a%.flac}.mp3"
>>
>>> done
>>>
>>> (add your other ffmpeg options as needed).
>>>
>>> Janis
>>>
>>
>
>
> what is this syntax
> "${a%.flac}.mp3"

The shell standard expression

${var%suffix}

is removing the 'suffix' (if present) from the variable 'var'.
The ".mp3" part is just a new suffix that gets concatenated.

Janis

Re: spaces in file names

<sbhe9l$rsj$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4008&group=comp.unix.shell#4008

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 11:42:13 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 23
Message-ID: <sbhe9l$rsj$1@news-1.m-online.net>
References: <samjbi$q3a$1@reader1.panix.com> <87y2b4bog0.fsf@bsb.me.uk>
<sbgcb8$6lh$4@reader1.panix.com>
NNTP-Posting-Host: 2001:a61:241e:cc01:5d6d:3b18:94fd:48be
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1625046133 28563 2001:a61:241e:cc01:5d6d:3b18:94fd:48be (30 Jun 2021 09:42:13 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Wed, 30 Jun 2021 09:42:13 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <sbgcb8$6lh$4@reader1.panix.com>
 by: Janis Papanagnou - Wed, 30 Jun 2021 09:42 UTC

On 30.06.2021 02:01, Popping Mad wrote:
> On 6/20/21 10:28 AM, Ben Bacarisse wrote:
>> For some reason the author is treating a as an array. This is harmless,
>> but unless I'm missing something, it's also pointless. You could write
>>
>> "${a/%flac/mp3}"
>>
>> instead. The ${var/s1/s2} syntax gives the value of $var but with the
>> first occurrence of s1 replaced by s2. In the % form (${var/%s1/s2}) s1
>> must match as the end of $var
>
>
> Excellent - thanks

Note that this is a non-standard construct (that you find in some
prominent shells, though), and note that it is unnecessary since
you can do that with a standard shell construct as well

"${a%flac}mp3"

Janis

Re: spaces in file names

<sbhee3$rsj$2@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4009&group=comp.unix.shell#4009

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 11:44:35 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 12
Message-ID: <sbhee3$rsj$2@news-1.m-online.net>
References: <samjbi$q3a$1@reader1.panix.com> <87y2b4bog0.fsf@bsb.me.uk>
<sbgc7p$6lh$3@reader1.panix.com>
NNTP-Posting-Host: 2001:a61:241e:cc01:5d6d:3b18:94fd:48be
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1625046275 28563 2001:a61:241e:cc01:5d6d:3b18:94fd:48be (30 Jun 2021 09:44:35 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Wed, 30 Jun 2021 09:44:35 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <sbgc7p$6lh$3@reader1.panix.com>
 by: Janis Papanagnou - Wed, 30 Jun 2021 09:44 UTC

On 30.06.2021 01:59, Popping Mad wrote:
> On 6/20/21 10:28 AM, Ben Bacarisse wrote:
>> The list that results from the ls command is subject to word splitting.
>
> and not from ./* ?

It's a question in which order the shell does the command processing
steps. Word splitting is done before pathname expansion from globbing.
(Google for or inspect the shell documentation for Command Processing.)

Janis

Re: spaces in file names

<sbhegu$rsj$3@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4010&group=comp.unix.shell#4010

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 11:46:06 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 16
Message-ID: <sbhegu$rsj$3@news-1.m-online.net>
References: <samjbi$q3a$1@reader1.panix.com>
<8335tc4fz1.fsf@helmutwaitzmann.news.arcor.de>
<443a4030-7548-0f27-c154-ec7bb1737b77@colition.gov>
NNTP-Posting-Host: 2001:a61:241e:cc01:5d6d:3b18:94fd:48be
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1625046367 28563 2001:a61:241e:cc01:5d6d:3b18:94fd:48be (30 Jun 2021 09:46:07 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Wed, 30 Jun 2021 09:46:07 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <443a4030-7548-0f27-c154-ec7bb1737b77@colition.gov>
 by: Janis Papanagnou - Wed, 30 Jun 2021 09:46 UTC

On 30.06.2021 02:03, Popping Mad wrote:
> On 6/20/21 1:13 PM, Helmut Waitzmann wrote:
>> for a in `ls ./*.flac`; do
>>
>> will not work (because of field splitting), neither will
>>
>> for a in "`ls ./*.flac`"; do
>
>
> but why is the default field split a space for the ls execution and not
> for ./* ?

Google for or inspect the shell documentation for Command Processing.

Janis

Re: spaces in file names

<sbhgar$siu$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4011&group=comp.unix.shell#4011

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 12:16:59 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 46
Message-ID: <sbhgar$siu$1@news-1.m-online.net>
References: <samjbi$q3a$1@reader1.panix.com>
<san3rs$mri$1@news-1.m-online.net> <satthq$6kj$1@reader2.panix.com>
<20210622174241.378@kylheku.com> <sbgbvg$6lh$1@reader1.panix.com>
NNTP-Posting-Host: 2001:a61:241e:cc01:5d6d:3b18:94fd:48be
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1625048219 29278 2001:a61:241e:cc01:5d6d:3b18:94fd:48be (30 Jun 2021 10:16:59 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Wed, 30 Jun 2021 10:16:59 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <sbgbvg$6lh$1@reader1.panix.com>
 by: Janis Papanagnou - Wed, 30 Jun 2021 10:16 UTC

On 30.06.2021 01:55, Popping Mad wrote:
> subject and ojects
>
> ./* is not a command in bash in of itself.
>
> for x in expects a list
>
> this is not a list ./*

No, this is not a list. It is a pattern that expands to a list of
matching filenames. The filenames may contain spaces, since field
splitting has already be performed at that stage and the semantic
entity of a filename is still preserved here.

>
> `ls ./*`
>
> does produce a list.

.* produces a list of matching files

ls ./* calls ls with the list of files and (depending on the options)
does several things with each of the arguments in the list
(and ls still sees the correct filename entities with spaces)

`ls ./*` calls a subshell and within it executes the given command
after having expanded the matching files for that command;
ls will see the filename entities because at the instance
of time when the filename expansion took place the field
splitting has already be done. The result of the command
execution from the subshell will then be expanded in a
sequence of words (not a sequence of filenames) separated
by a blank (per default), since the field splitting will
then happen (in the outer shell context; you should be
aware that we have two levels of shell instances with the
`...` construct here - to make that fact apparent is one
of many reasons to use $(...) instead as the modern/better
alternative, but which of course behaves equivalently with
respect to field splitting).

> That is how I think about it. Obviously, I am wrong.

Obviously.

Janis

Re: spaces in file names

<87wnqbk4jw.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4012&group=comp.unix.shell#4012

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 11:52:35 +0100
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <87wnqbk4jw.fsf@bsb.me.uk>
References: <samjbi$q3a$1@reader1.panix.com> <87y2b4bog0.fsf@bsb.me.uk>
<sbgcb8$6lh$4@reader1.panix.com> <sbhe9l$rsj$1@news-1.m-online.net>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="865a328425aee9c8c65edcd9132779d2";
logging-data="5845"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2JUmhpy/c1BgiWWpFdd9YbYJDDXrnqJA="
Cancel-Lock: sha1:Qbx9M6KtDh3GAP/r3Fu0mt7x5uY=
sha1:3+zdsYVwiOf13TxAM9m6uPUQV58=
X-BSB-Auth: 1.7a30c76c60d4ef916ee6.20210630115235BST.87wnqbk4jw.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 30 Jun 2021 10:52 UTC

Janis Papanagnou <janis_papanagnou@hotmail.com> writes:

> On 30.06.2021 02:01, Popping Mad wrote:
>> On 6/20/21 10:28 AM, Ben Bacarisse wrote:
>>> For some reason the author is treating a as an array. This is harmless,
>>> but unless I'm missing something, it's also pointless. You could write
>>>
>>> "${a/%flac/mp3}"
>>>
>>> instead. The ${var/s1/s2} syntax gives the value of $var but with the
>>> first occurrence of s1 replaced by s2. In the % form (${var/%s1/s2}) s1
>>> must match as the end of $var
>>
>>
>> Excellent - thanks
>
> Note that this is a non-standard construct (that you find in some
> prominent shells, though), and note that it is unnecessary since
> you can do that with a standard shell construct as well
>
> "${a%flac}mp3"

I held off suggesting that because it does not do exactly the same
thing. Won't matter in this case (the OP loops over ".flac" files) but
then they also said they were using bash.

--
Ben.

Re: spaces in file names

<sbho1s$uo2$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4013&group=comp.unix.shell#4013

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.mixmin.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 14:28:44 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 48
Message-ID: <sbho1s$uo2$1@news-1.m-online.net>
References: <samjbi$q3a$1@reader1.panix.com> <87y2b4bog0.fsf@bsb.me.uk>
<sbgcb8$6lh$4@reader1.panix.com> <sbhe9l$rsj$1@news-1.m-online.net>
<87wnqbk4jw.fsf@bsb.me.uk>
NNTP-Posting-Host: 2001:a61:241e:cc01:5d6d:3b18:94fd:48be
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1625056124 31490 2001:a61:241e:cc01:5d6d:3b18:94fd:48be (30 Jun 2021 12:28:44 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Wed, 30 Jun 2021 12:28:44 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <87wnqbk4jw.fsf@bsb.me.uk>
 by: Janis Papanagnou - Wed, 30 Jun 2021 12:28 UTC

On 30.06.2021 12:52, Ben Bacarisse wrote:
> Janis Papanagnou <janis_papanagnou@hotmail.com> writes:
>
>> On 30.06.2021 02:01, Popping Mad wrote:
>>> On 6/20/21 10:28 AM, Ben Bacarisse wrote:
>>>> For some reason the author is treating a as an array. This is harmless,
>>>> but unless I'm missing something, it's also pointless. You could write
>>>>
>>>> "${a/%flac/mp3}"
>>>>
>>>> instead. The ${var/s1/s2} syntax gives the value of $var but with the
>>>> first occurrence of s1 replaced by s2. In the % form (${var/%s1/s2}) s1
>>>> must match as the end of $var
>>>
>>>
>>> Excellent - thanks
>>
>> Note that this is a non-standard construct (that you find in some
>> prominent shells, though), and note that it is unnecessary since
>> you can do that with a standard shell construct as well
>>
>> "${a%flac}mp3"
>
> I held off suggesting that because it does not do exactly the same
> thing. Won't matter in this case (the OP loops over ".flac" files) but
> then they also said they were using bash.

I haven't meant to say that these two code patterns would do the same.
(Actually, I haven't even pondered about that question; mainly because
the non-standard code pattern wasn't really necessary here.)

Why use "${a/%flac/mp3}" in the first place?

Generally, if I can use a standard construct for a given case without
any negative effects (that some non-standard construct might address),
I go for the standard. (YMMV.) And that's independent of the shell I
use. (I use ksh, a shell much more powerful than standard sh or bash;
nonetheless I restrict myself as much as possible - but it should not
hurt! :-) - to feature subsets of the prominent shells (incl. bash)
or even standard sh; as said, if it doesn't hurt.)

For example I regularly use the non-standard ${var/s1/s2} because all
the standard counterparts are inefficient or bulky. But here the good
old ${a%s} is fine and there's no need (for me) to introduce something
else that is more "complex" and non-standard.

Janis

Re: spaces in file names

<sbhpc3$2so1j$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4014&group=comp.unix.shell#4014

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!2.eu.feeder.erje.net!feeder.erje.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 12:51:16 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sbhpc3$2so1j$1@news.xmission.com>
References: <samjbi$q3a$1@reader1.panix.com> <87y2b4bog0.fsf@bsb.me.uk> <sbgcb8$6lh$4@reader1.panix.com> <sbhe9l$rsj$1@news-1.m-online.net>
Injection-Date: Wed, 30 Jun 2021 12:51:16 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3039283"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Wed, 30 Jun 2021 12:51 UTC

In article <sbhe9l$rsj$1@news-1.m-online.net>,
Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
....
>Note that this is a non-standard construct (that you find in some
>prominent shells, though), and note that it is unnecessary since
>you can do that with a standard shell construct as well
>
> "${a%flac}mp3"

Yes, but the replacement syntax is more appealing to the eye - and makes
more intuitive sense.

I.e., my mindset is "replace this with that", not "remove this" and then
"append that". Yes, I know they are equivalent, but I think it is worth
using something "non-standard" to get some mental clarity.

Going "non-standard" don't upset me much...

--
Trump has normalized hate.

The media has normalized Trump.

Re: spaces in file names

<sbhpjv$2so1j$2@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4015&group=comp.unix.shell#4015

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 12:55:27 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sbhpjv$2so1j$2@news.xmission.com>
References: <samjbi$q3a$1@reader1.panix.com> <san8k2$o5p$2@news-1.m-online.net> <sbgbjf$7v3$1@reader1.panix.com> <sbhdrn$rrr$1@news-1.m-online.net>
Injection-Date: Wed, 30 Jun 2021 12:55:27 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3039283"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Wed, 30 Jun 2021 12:55 UTC

In article <sbhdrn$rrr$1@news-1.m-online.net>,
Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
....
>The shell standard expression
>
> ${var%suffix}
>
>is removing the 'suffix' (if present) from the variable 'var'.
>The ".mp3" part is just a new suffix that gets concatenated.

Actually, it does not remove it from the variable 'var'; the original
contents is kept intact. All it does is return a string contructed from
the contents of the variable, with the 'suffic' removed.

--
Christianity is not a religion.

- Rick C Hodgin -

Re: spaces in file names

<sbht6q$hj$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4016&group=comp.unix.shell#4016

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 15:56:42 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 23
Message-ID: <sbht6q$hj$1@news-1.m-online.net>
References: <samjbi$q3a$1@reader1.panix.com>
<san8k2$o5p$2@news-1.m-online.net> <sbgbjf$7v3$1@reader1.panix.com>
<sbhdrn$rrr$1@news-1.m-online.net> <sbhpjv$2so1j$2@news.xmission.com>
NNTP-Posting-Host: 2001:a61:241e:cc01:5d6d:3b18:94fd:48be
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1625061402 563 2001:a61:241e:cc01:5d6d:3b18:94fd:48be (30 Jun 2021 13:56:42 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Wed, 30 Jun 2021 13:56:42 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <sbhpjv$2so1j$2@news.xmission.com>
 by: Janis Papanagnou - Wed, 30 Jun 2021 13:56 UTC

On 30.06.2021 14:55, Kenny McCormack wrote:
> In article <sbhdrn$rrr$1@news-1.m-online.net>,
> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
> ...
>> The shell standard expression
>>
>> ${var%suffix}
>>
>> is removing the 'suffix' (if present) from the variable 'var'.
>> The ".mp3" part is just a new suffix that gets concatenated.
>
> Actually, it does not remove it from the variable 'var'; the original
> contents is kept intact. All it does is return a string contructed from
> the contents of the variable, with the 'suffic' removed.

Right. Thanks for fixing my formally imperfect explanation.

These substitutions (at least the standard ones) all work the way
you describe, with the exception of ${var=val} and ${var:=val}
that do an assignment to the variable.

Janis

Re: spaces in file names

<sbhte7$i3$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4017&group=comp.unix.shell#4017

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 16:00:39 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 25
Message-ID: <sbhte7$i3$1@news-1.m-online.net>
References: <samjbi$q3a$1@reader1.panix.com> <87y2b4bog0.fsf@bsb.me.uk>
<sbgcb8$6lh$4@reader1.panix.com> <sbhe9l$rsj$1@news-1.m-online.net>
<sbhpc3$2so1j$1@news.xmission.com>
NNTP-Posting-Host: 2001:a61:241e:cc01:5d6d:3b18:94fd:48be
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1625061639 579 2001:a61:241e:cc01:5d6d:3b18:94fd:48be (30 Jun 2021 14:00:39 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Wed, 30 Jun 2021 14:00:39 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <sbhpc3$2so1j$1@news.xmission.com>
 by: Janis Papanagnou - Wed, 30 Jun 2021 14:00 UTC

On 30.06.2021 14:51, Kenny McCormack wrote:
> In article <sbhe9l$rsj$1@news-1.m-online.net>,
> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
> ...
>> Note that this is a non-standard construct (that you find in some
>> prominent shells, though), and note that it is unnecessary since
>> you can do that with a standard shell construct as well
>>
>> "${a%flac}mp3"
>
> Yes, but the replacement syntax is more appealing to the eye - and makes
> more intuitive sense.

I also think that intuitive clarity is a factor to consider. The
concrete preferred code pattern certainly depends on the individual
(and probably also on the code context).

> I.e., my mindset is "replace this with that", not "remove this" and then
> "append that". Yes, I know they are equivalent, but I think it is worth
> using something "non-standard" to get some mental clarity.
>
> Going "non-standard" don't upset me much...

Janis

Why 'for v in `ls ...` ; do ... ; done' won't work: command substitution and field splitting (was: spaces in file names)

<83tulfglou.fsf_-_@helmutwaitzmann.news.arcor.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4018&group=comp.unix.shell#4018

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!B+jpmyJZr9GNcsClS8/Qog.user.gioia.aioe.org.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Why 'for v in `ls ...` ; do ... ; done' won't work: command substitution and field splitting (was: spaces in file names)
Date: Wed, 30 Jun 2021 22:08:17 +0200
Organization: Aioe.org NNTP Server
Lines: 191
Message-ID: <83tulfglou.fsf_-_@helmutwaitzmann.news.arcor.de>
References: <samjbi$q3a$1@reader1.panix.com>
<8335tc4fz1.fsf@helmutwaitzmann.news.arcor.de>
<sbgcfp$6lh$6@reader1.panix.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
NNTP-Posting-Host: B+jpmyJZr9GNcsClS8/Qog.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Complaints-To: abuse@aioe.org
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
X-Notice: Filtered by postfilter v. 0.9.2
Mail-Copies-To: nobody
Cancel-Lock: sha1:nQXJ9LICaFy2uxgGgvjAsP4km2o=
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
 by: Helmut Waitzmann - Wed, 30 Jun 2021 20:08 UTC

Popping Mad <rainbow@colition.gov>:
>On 6/20/21 1:13 PM, Helmut Waitzmann wrote:

>>   for a in `ls ./*.flac`; do
>>
>> will not work (because of field splitting), neither will
>>
>>
>>   for a in "`ls ./*.flac`"; do
>
>
>but why is the default field split a space for the ls execution and
>not for ./* ?

Please look up
<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/toc.html>,
which is the detailed table of contents of the ‘Shell & Utilities’
document of the POSIX standard.

In this table of contents, look for the ‘Shell Command Language’
chapter, which describes the behavior of the shell.  (The following
URLs denote parts of that chapter.)

In the commandline

for a in ./*.flac ; do echo "$a" ; done

the shell will recognize the unquoted string ‘./*.flac’ as a
pathname pattern (because of the ‘*’, see
<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13>)
and expand it as described in
<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_06>,
thus getting a list of pathnames.

The shell will assign the variable ‘a’ each of the pathnames, one
at a time, and invoke the ‘echo’ command with that pathname as a
parameter.

On the other hand, in the commandline

for a in `ls ./*.flac` ; do echo "$a" ; done

the shell will recognize the ‘`…`’ as command substitution
(<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_03>): 
It will invoke a subshell environment, which will parse the

ls ./*.flac

commandline.  Like above, the subshell will recognize the unquoted
string ‘./*.flac’ as a pathname pattern and expand it, thus invoking
the ‘ls’ utility on a list of pathnames.

The ‘ls’ utility will lookup each of the given pathnames and output
some information (for example the name) of each pathname, separated
by a newline.

For example, if in the current directory there are two regular files
with filenames

‘a file.flac’

(containing a space character) and

‘a
twoliner.flac’

(containing a newline character) respectively.  Then the output of

ls *.flac

will be the following three lines:

../a file.flac
../a
twoliner.flac

As you can already see, there is no way for you to tell from the
output of the ‘ls’ utility, whether ‘ls’ has seen one (strange but
valid) filename:

‘./a file.flac
../a
twoliner.flac’

or two filenames:

‘./a file.flac’

and

‘./a
twoliner.flac’

or even three filenames:

‘./a file.flac’,

‘./a’,

and

‘twoliner.flac’.

And of course the shell won't be able to distinguish those three
cases, as well:

If you use the commandline

for a in "`ls …`" ; do

(note the double quotes) then the shell will not do any field
splitting on the output of the ‘ls’ command, i. e. it will interpret
the output of the ‘ls’ command as the threeliner pathname

‘./a file.flac
../a
twoliner.flac’.

If on the other hand you use the commandline

for a in `ls …` ; do

then the shell will do field splitting on the output of the ‘ls’
command, i. e. it will split that output at each white space
character (blanks, tabs and newlines; more precisely: according to
the characters that are part of the value of the ‘IFS’ shell
variable, which by default are blanks, tabs, and newlines; see
<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05>). 

Thus it will assign the variable ‘a’ the values ‘./a’,
‘file.flac’, ‘./a’, and ‘twoliner.flac’, one at a time.

=> Neither the ‘"`ls`"’ nor the ‘`ls`’ variant will preserve the
original filenames.  Both of them will just not work.

To come back to your question:

>but why is the default field split a space for the ls execution and
>not for ./* ?

If you use the commandline

for a in ./*.flac ; do echo "$a" ; done

then the shell will gather the matching pathnames and assign them to
the variable ‘a’ one at a time, invoking the ‘echo’ command for each
of the pathnames.  The pathnames are neither glued together (with
newlines in between like ‘ls’ does), nor are they undergone field
splitting.

=> The pathnames are left intact.

Re: spaces in file names

<87o8bnj7zp.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4019&group=comp.unix.shell#4019

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Wed, 30 Jun 2021 23:35:54 +0100
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <87o8bnj7zp.fsf@bsb.me.uk>
References: <samjbi$q3a$1@reader1.panix.com> <87y2b4bog0.fsf@bsb.me.uk>
<sbgcb8$6lh$4@reader1.panix.com> <sbhe9l$rsj$1@news-1.m-online.net>
<87wnqbk4jw.fsf@bsb.me.uk> <sbho1s$uo2$1@news-1.m-online.net>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="a2d8b1c21ccbe83bdb1b6c6beabf5900";
logging-data="13759"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fAK/sMEvE1m5eHEGan5C5h/UBScrLPOk="
Cancel-Lock: sha1:Y4bh7BNIOeWk75H13e3AWkFJh3E=
sha1:Wy3GKlLFM0BITwI9jhXocdEuciw=
X-BSB-Auth: 1.6cef1e2b88622ec0102d.20210630233554BST.87o8bnj7zp.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 30 Jun 2021 22:35 UTC

Janis Papanagnou <janis_papanagnou@hotmail.com> writes:

> On 30.06.2021 12:52, Ben Bacarisse wrote:
>> Janis Papanagnou <janis_papanagnou@hotmail.com> writes:
>>
>>> On 30.06.2021 02:01, Popping Mad wrote:
>>>> On 6/20/21 10:28 AM, Ben Bacarisse wrote:
>>>>> For some reason the author is treating a as an array. This is harmless,
>>>>> but unless I'm missing something, it's also pointless. You could write
>>>>>
>>>>> "${a/%flac/mp3}"
>>>>>
>>>>> instead. The ${var/s1/s2} syntax gives the value of $var but with the
>>>>> first occurrence of s1 replaced by s2. In the % form (${var/%s1/s2}) s1
>>>>> must match as the end of $var
>>>>
>>>>
>>>> Excellent - thanks
>>>
>>> Note that this is a non-standard construct (that you find in some
>>> prominent shells, though), and note that it is unnecessary since
>>> you can do that with a standard shell construct as well
>>>
>>> "${a%flac}mp3"
>>
>> I held off suggesting that because it does not do exactly the same
>> thing. Won't matter in this case (the OP loops over ".flac" files) but
>> then they also said they were using bash.
>
> I haven't meant to say that these two code patterns would do the same.
> (Actually, I haven't even pondered about that question; mainly because
> the non-standard code pattern wasn't really necessary here.)
>
> Why use "${a/%flac/mp3}" in the first place?

We may never know. The OP posted code from someone else and asked about
what it meant. I was explaining it. I stopped short of correcting it.

--
Ben.

Re: spaces in file names

<scqn48$3it$1@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4119&group=comp.unix.shell#4119

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.www3.mrbrklyn.com!not-for-mail
From: rain...@colition.gov (Popping Mad)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Thu, 15 Jul 2021 21:23:08 -0400
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <scqn48$3it$1@reader1.panix.com>
References: <samjbi$q3a$1@reader1.panix.com>
<san3rs$mri$1@news-1.m-online.net> <satthq$6kj$1@reader2.panix.com>
<20210622174241.378@kylheku.com> <sbgbvg$6lh$1@reader1.panix.com>
<sbgvak$b1b$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 16 Jul 2021 01:24:24 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="www3.mrbrklyn.com:96.57.23.83";
logging-data="3677"; mail-complaints-to="abuse@panix.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
In-Reply-To: <sbgvak$b1b$1@dont-email.me>
Content-Language: en-US
 by: Popping Mad - Fri, 16 Jul 2021 01:23 UTC

On 6/30/21 1:26 AM, William Unruh wrote:
> actually
> for x in ./*
> is a list. The shell expands ./* before it runs the command (for x in)
> so that will produce a whole list of items -- all of the filenames that
> do not start with . in the current directory.
> Try
> for i in ./*
> do
> echo $i
> done

I thought that only happened when their is a command to take the glob as
an argument. I didn't know that the shell takes that as a command.

Re: spaces in file names

<scqn6e$3it$2@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4120&group=comp.unix.shell#4120

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.www3.mrbrklyn.com!not-for-mail
From: rain...@colition.gov (Popping Mad)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Thu, 15 Jul 2021 21:24:18 -0400
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <scqn6e$3it$2@reader1.panix.com>
References: <samjbi$q3a$1@reader1.panix.com>
<san3rs$mri$1@news-1.m-online.net> <satthq$6kj$1@reader2.panix.com>
<20210622174241.378@kylheku.com> <sbgbvg$6lh$1@reader1.panix.com>
<sbhgar$siu$1@news-1.m-online.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 16 Jul 2021 01:25:34 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="www3.mrbrklyn.com:96.57.23.83";
logging-data="3677"; mail-complaints-to="abuse@panix.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
In-Reply-To: <sbhgar$siu$1@news-1.m-online.net>
Content-Language: en-US
 by: Popping Mad - Fri, 16 Jul 2021 01:24 UTC

On 6/30/21 6:16 AM, Janis Papanagnou wrote:
> On 30.06.2021 01:55, Popping Mad wrote:
>> subject and ojects
>>
>> ./* is not a command in bash in of itself.
>>
>> for x in expects a list
>>
>> this is not a list ./*
>
> No, this is not a list. It is a pattern that expands to a list of
> matching filenames. The filenames may contain spaces, since field
> splitting has already be performed at that stage and the semantic
> entity of a filename is still preserved here.
>
>>
>> `ls ./*`
>>
>> does produce a list.
>
> .* produces a list of matching files
>
> ls ./* calls ls with the list of files and (depending on the options)
> does several things with each of the arguments in the list
> (and ls still sees the correct filename entities with spaces)
>
> `ls ./*` calls a subshell and within it executes the given command
> after having expanded the matching files for that command;
> ls will see the filename entities because at the instance
> of time when the filename expansion took place the field
> splitting has already be done. The result of the command
> execution from the subshell will then be expanded in a
> sequence of words (not a sequence of filenames) separated
> by a blank (per default), since the field splitting will
> then happen (in the outer shell context; you should be
> aware that we have two levels of shell instances with the
> `...` construct here - to make that fact apparent is one
> of many reasons to use $(...) instead as the modern/better
> alternative, but which of course behaves equivalently with
> respect to field splitting).
>
>> That is how I think about it. Obviously, I am wrong.
>
> Obviously.
>
> Janis
>

Thanks!

Re: spaces in file names

<sct9ca$e2k$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4121&group=comp.unix.shell#4121

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Sat, 17 Jul 2021 02:48:10 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 27
Message-ID: <sct9ca$e2k$1@news-1.m-online.net>
References: <samjbi$q3a$1@reader1.panix.com>
<san3rs$mri$1@news-1.m-online.net> <satthq$6kj$1@reader2.panix.com>
<20210622174241.378@kylheku.com> <sbgbvg$6lh$1@reader1.panix.com>
<sbgvak$b1b$1@dont-email.me> <scqn48$3it$1@reader1.panix.com>
NNTP-Posting-Host: 2001:a61:241e:cc01:c59b:acc:8089:1b95
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1626482890 14420 2001:a61:241e:cc01:c59b:acc:8089:1b95 (17 Jul 2021 00:48:10 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Sat, 17 Jul 2021 00:48:10 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <scqn48$3it$1@reader1.panix.com>
 by: Janis Papanagnou - Sat, 17 Jul 2021 00:48 UTC

On 16.07.2021 03:23, Popping Mad wrote:
> On 6/30/21 1:26 AM, William Unruh wrote:
>> actually
>> for x in ./*
>> is a list. The shell expands ./* before it runs the command (for x in)
>> so that will produce a whole list of items -- all of the filenames that
>> do not start with . in the current directory.
>> Try
>> for i in ./*
>> do
>> echo $i
>> done
>
> I thought that only happened when their is a command to take the glob as
> an argument. I didn't know that the shell takes that as a command.

Could it be that you are coming from the Windows/DOS world?
I am asking because in DOS (AFAIR) it had been the case that the
command line was (WRT the "wildcard" characters * and ? ) literally
passed to the command, and it was every _command's_ responsibility
(as opposed to the shell or "command interpreter") to expand the
"wildcard" characters to create file lists. In Unix the shell does
these (and other) expansions. - Could that have been the source of
your confusion?

Janis

Re: spaces in file names

<slrnsf5hde.uqc.whynot@orphan.zombinet>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4122&group=comp.unix.shell#4122

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: why...@pozharski.name (Eric Pozharski)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Sat, 17 Jul 2021 11:57:34 +0000
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <slrnsf5hde.uqc.whynot@orphan.zombinet>
References: <samjbi$q3a$1@reader1.panix.com>
<san3rs$mri$1@news-1.m-online.net> <satthq$6kj$1@reader2.panix.com>
<20210622174241.378@kylheku.com> <sbgbvg$6lh$1@reader1.panix.com>
<sbgvak$b1b$1@dont-email.me> <scqn48$3it$1@reader1.panix.com>
<sct9ca$e2k$1@news-1.m-online.net>
Injection-Info: reader02.eternal-september.org; posting-host="f53f5d229ce9b7893ace915e4077170d";
logging-data="18288"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dYZV3evw09aYwOIlDNYsI"
User-Agent: slrn/pre1.0.0-18 (Linux)
Cancel-Lock: sha1:I9JUtGo7oLnhPbS9MA61kNUxeKQ=
 by: Eric Pozharski - Sat, 17 Jul 2021 11:57 UTC

with <sct9ca$e2k$1@news-1.m-online.net> Janis Papanagnou wrote:
> On 16.07.2021 03:23, Popping Mad wrote:
>> On 6/30/21 1:26 AM, William Unruh wrote:

>>> actually for x in ./* is a list. The shell expands ./* before it
>>> runs the command (for x in) so that will produce a whole list of
>>> items -- all of the filenames that do not start with . in the
>>> current directory.
*SKIP*
>> I thought that only happened when their is a command to take the glob
>> as an argument. I didn't know that the shell takes that as a
>> command.
> Could it be that you are coming from the Windows/DOS world? I am
> asking because in DOS (AFAIR) it had been the case that the command
> line was (WRT the "wildcard" characters * and ? ) literally passed to
> the command, and it was every _command's_ responsibility (as opposed
> to the shell or "command interpreter") to expand the "wildcard"
> characters to create file lists. In Unix the shell does these (and
> other) expansions. - Could that have been the source of your
> confusion?

s/had been/is/ s/was/is/g

Also, handling of command line by GUI isn't any better and there's no
escaping (only double-quotes that act like as single-quotes in the
shell). As a result charging multiple files with spaces in filenames
will ensue extreme frustration for non-mouse-massaging types.

--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

Re: spaces in file names

<krs1qn9a.j4ygwo@bdesham.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4197&group=comp.unix.shell#4197

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: use...@esham.io (Benjamin Esham)
Newsgroups: comp.unix.shell
Subject: Re: spaces in file names
Date: Sat, 31 Jul 2021 14:14:56 -0400
Organization: United Federation of Planets
Lines: 27
Message-ID: <krs1qn9a.j4ygwo@bdesham.net>
References: <samjbi$q3a$1@reader1.panix.com>
<86pmwguqr4.fsf@red.stonehenge.com>
<barmar-EC6F5A.15211426062021@reader.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="2e831791385651d0acd6b1473b4cc64e";
logging-data="18320"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Sm5hkjN5yWN/NFRBw9STru/aqRA8in0QJ3C87YGh8mA=="
User-Agent: Gnus/5.13 (macOS)
Cancel-Lock: sha1:oe8nMmBB5DobP0xk5dQVx7KUupw=
sha1:tVoxF7zzEwCN6dYm0BmHnkXzxJ4=
 by: Benjamin Esham - Sat, 31 Jul 2021 18:14 UTC

Barry Margolin wrote:

> In article <86pmwguqr4.fsf@red.stonehenge.com>, merlyn@stonehenge.com
> (Randal L. Schwartz) wrote:
>
>> You think spaces in filenames are weird? I often made a habit of making
>> a directory named \n (well, a literal newline) to test my shell scripts.
>> I figured if they could deal with a newline, they could probably deal
>> with most other things. Also to freak out people peeking at my $HOME. :)
>
> If you really want to freak them out, put \r in the filenames.

macOS lets users assign custom icons to files and folders. When you do it
for a folder, the system stores the icon in the folder in a file named
"Icon\r", with a 0D byte at the end. These files are hidden in most
contexts, but occasionally an application will include one in a file
listing, and then you usually see the bottom half of the word "Icon" with a
weird space under it.

(It looks like you're posting from a Mac, so maybe you were alluding to
this.)

The built-in (BSD) ls renders these files as Icon? in file listings, which
is... not super helpful. GNU ls and exa both display the name more
explicitly, as 'Icon'$'\r' or Icon\r (with the \r in red), respectively.

Benjamin

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor