help-bash
[Top][All Lists]
Advanced

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

Re: case $var in $list) issue


From: Greg Wooledge
Subject: Re: case $var in $list) issue
Date: Fri, 1 Nov 2024 22:42:47 -0400

On Fri, Nov 01, 2024 at 22:22:28 -0400, Zachary Santer wrote:
> I guess an easy workaround would be to just
> IFS=':'
> PATH_and_colon="${PATH}:"
> for directory in ${PATH_and_colon}; do
>   # whatever
> done

Congratulations, you've discovered Pitfall #47.
<https://mywiki.wooledge.org/BashPitfalls#pf47>

You've found the correct workaround as well.

Of course, if you're going to use an unquoted variable expansion and count
on IFS for field splitting, you also need to disable filename expansion
(set -f) to protect against glob characters.

Unquoted expansions and unusual IFS settings tend to reveal all kinds
of shell bugs, so beware of that.  Whenever possible, I will look for
*any* other solution that doesn't require unquoted expansions.



reply via email to

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