bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: select syntax violates the POLA


From: Greg Wooledge
Subject: Re: select syntax violates the POLA
Date: Thu, 1 Apr 2021 11:36:14 -0400

On Thu, Apr 01, 2021 at 01:36:59AM -0700, greywolf@starwolf.com wrote:
>       The following is valid shell code:
> 
>       d=($(ls /usr/src/pkg/*/$1));

Syntactically valid, but semantically wrong.

If $1 is not a directory, then you want:

d=(/usr/src/pkg/*/"$1")

If $1 is supposed to be a directory, and therefore you want only filenames
and not full pathnames in the array, then we can arrange for that as well,
but it's slightly more tedious.

Using ls here is wrong, and will break.  It's Pitfall #1 on my list for
a reason.

https://mywiki.wooledge.org/BashPitfalls#pf1

>       cd ${dir} &&

Quotes.

>       make clean && {
>           make update ||
>           make install;
>       }

Is the inner || supposed to be && by chance?

>       if ((n > 1)); then {
>           select dir in ${d[@]}; do {
>               break;
>           } done;
>       }

"${d[@]}" with quotes.

What purpose do the extra curly braces serve?  Do you want them just
because you think they look pretty?

>       until [ -f ${tmpfile} ]; do {

Quotes.  And again, those extra curly braces don't serve any purpose.

>       for dir in ${d[@]}; do {

Quotes.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]