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

Re: Bash: testing a variable



On Fri, Jul 09, 2021 at 02:45:23PM -0600, Charles Curley wrote:
> On Fri, 9 Jul 2021 16:25:11 -0400
> Greg Wooledge <greg@wooledge.org> wrote:
> 
> > add_path_maybe() {
> >   local p i
> > ...
> 
> Very nice, sir. Thank you.
> 
> shellcheck complained about the redirection in the "IFS=: read" line,
> but I'm not going to worry about that.

Since it's a function, and not a script, there's no shebang.  So I'm
guessing shellcheck assumed it was /bin/sh code, rather than bash code.
<<< is just one of the bashisms I used here.  local is another.  The
use of arrays is a third.  The [[ command is a fourth.

The traditional way of doing this in sh involves pattern-matching
:$PATH: against *:/your/dir:* instead of splitting the PATH into array
elements and iterating over them.  It's an ugly hack, which is basically
what you always have to do in sh, because it lacks so many features.


Reply to: