Set bash's shell option nullglob by default?

2012-07-13 Thread Roman Rakus

Hi,
I have a question about nullglob bash's shell option. I want to hear 
opinions.

The behavior is nicely described in bash reference manual [1]
By default, the nullglob is turned off. And it tends people to use bad 
habits in shell scripting.
In my POV the nullglob could be turned on by default. However, i would 
like to hear opinions from others.


It is possible it can break many scripts even in rpm's scriptlets, but 
as I already said, it's because bad habits. So the main gain will be the 
people will learn how is the globbing in bash and in the whole 
environment working.


RR

[1] http://www.gnu.org/software/bash/manual/bashref.html#Filename-Expansion

--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel

Re: Set bash's shell option nullglob by default?

2012-07-13 Thread Scott Schmit
On Fri, Jul 13, 2012 at 01:56:29PM +0200, Roman Rakus wrote:
 Hi,
 I have a question about nullglob bash's shell option. I want to hear
 opinions.
 The behavior is nicely described in bash reference manual [1]
 By default, the nullglob is turned off. And it tends people to use
 bad habits in shell scripting.
 In my POV the nullglob could be turned on by default. However, i
 would like to hear opinions from others.
 
 It is possible it can break many scripts even in rpm's scriptlets,
 but as I already said, it's because bad habits. So the main gain
 will be the people will learn how is the globbing in bash and in the
 whole environment working.

So ls *.foo should list the entire directory if no files match *.foo?
It's a bad habit for me to expect ls *.foo to return nothing in this
case? You're going to need to convince me.

-- 
Scott Schmit


smime.p7s
Description: S/MIME cryptographic signature
-- 
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel

Re: Set bash's shell option nullglob by default?

2012-07-13 Thread Roman Rakus

On 07/13/2012 02:06 PM, Scott Schmit wrote:

So ls *.foo should list the entire directory if no files match *.foo?
It's a bad habit for me to expect ls *.foo to return nothing in this
case? You're going to need to convince me.
And if there are directories ending with .foo? Hopefully you are not 
using such things in scripts.

OK, in interactive shells `ls *' is not that wrong.

printf '%s\n' *.foo
for file in *.foo; do ... done

RR
--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel

Re: Set bash's shell option nullglob by default?

2012-07-13 Thread Tomas Mraz
On Fri, 2012-07-13 at 13:56 +0200, Roman Rakus wrote: 
 Hi,
 I have a question about nullglob bash's shell option. I want to hear 
 opinions.
 The behavior is nicely described in bash reference manual [1]
 By default, the nullglob is turned off. And it tends people to use bad 
 habits in shell scripting.
 In my POV the nullglob could be turned on by default. However, i would 
 like to hear opinions from others.

This could cause serious surprising breakages of scripts with strange
consequences. I'm strictly against this change. If something at all
should be changed in this regard to break bad habits then it should be
the failglob option although I am not convinced that it is too good idea
either.
-- 
Tomas Mraz
No matter how far down the wrong road you've gone, turn back.
  Turkish proverb

-- 
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel

Re: Set bash's shell option nullglob by default?

2012-07-13 Thread Roman Rakus

On 07/13/2012 02:19 PM, Tomas Mraz wrote:

This could cause serious surprising breakages of scripts with strange
consequences. I'm strictly against this change. If something at all
should be changed in this regard to break bad habits then it should be
the failglob option although I am not convinced that it is too good idea
either.

I was thinking about failglob also, but it is not that useful like it looks.

for name in *; do ...; done

In the current state, if there isn't any file, the name variable will 
contain *.

With nullglob name will be empty and script continues after the for loop.
With failglob it will print error message. I think it is not useful.

But you are right, it will cause many breakages (even surprising).

RR
--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel

Re: Set bash's shell option nullglob by default?

2012-07-13 Thread Bryn M. Reeves
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 07/13/2012 01:06 PM, Scott Schmit wrote:
 On Fri, Jul 13, 2012 at 01:56:29PM +0200, Roman Rakus wrote:
 Hi, I have a question about nullglob bash's shell option. I want
 to hear opinions. The behavior is nicely described in bash
 reference manual [1] By default, the nullglob is turned off. And
 it tends people to use bad habits in shell scripting. In my POV
 the nullglob could be turned on by default. However, i would like
 to hear opinions from others.
 
 It is possible it can break many scripts even in rpm's
 scriptlets, but as I already said, it's because bad habits. So
 the main gain will be the people will learn how is the globbing
 in bash and in the whole environment working.
 
 So ls *.foo should list the entire directory if no files match
 *.foo? It's a bad habit for me to expect ls *.foo to return nothing
 in this case? You're going to need to convince me.

I wouldn't back this change either but that's not the behaviour of
nullglob. If nothing matches the glob the word remains unchanged (i.e.
*.foo - *.foo):

$ ls *.foo
ls: cannot access *.foo: No such file or directory

$ echo *.foo
*.foo

Regards,
Bryn.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlAAFTIACgkQ6YSQoMYUY956BgCgicpLdJr4nM7NBwYOSJS9kQVe
8qoAoJKEtqaWJ0SAbT2UXK7URkSaxXV+
=H6xC
-END PGP SIGNATURE-
-- 
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel

Re: Set bash's shell option nullglob by default?

2012-07-13 Thread Bryn M. Reeves
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 07/13/2012 01:31 PM, Bryn M. Reeves wrote:
 I wouldn't back this change either but that's not the behaviour of 
 nullglob. If nothing matches the glob the word remains unchanged
 (i.e. *.foo - *.foo):

Eh, nevermind.. not enough coffee.

Bryn.

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlAAFYMACgkQ6YSQoMYUY94DnACgkaZ3RgDOq98rMsVREgwYMBnG
fokAoI9qRfmYOpIv9wzq7u7VMCMCq1zv
=MTCR
-END PGP SIGNATURE-
-- 
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel

Re: Set bash's shell option nullglob by default?

2012-07-13 Thread Björn Persson
Roman Rakus wrote:
 By default, the nullglob is turned off. And it tends people to use bad 
 habits in shell scripting.

What habits exactly, and why are those habits bad?

 In my POV the nullglob could be turned on by default. However, i would 
 like to hear opinions from others.

Changing a programming language under the programmers' feet it almost never a 
good idea. Shall I start setting all Bash options explicitly in every single 
shell script just so that I'll know how the language works even if someone 
changes the defaults on me?

Björn Persson


signature.asc
Description: This is a digitally signed message part.
-- 
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel

Re: Set bash's shell option nullglob by default?

2012-07-13 Thread David Levine
Roman wrote:

 It is possible it can break many scripts even in rpm's
 scriptlets, but as I already said, it's because bad
 habits. So the main gain will be the people will learn how
 is the globbing in bash and in the whole environment
 working.

Please don't.  If an author or maintainer wants to save
themself from bad habits, they can put shopt -s nullglob
near the top of their bash scripts.

Let's not break many, many existing scripts.

David
-- 
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel