help-bash
[Top][All Lists]
Advanced

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

Re: Verifying numeric values


From: Andreas Kusalananda Kähäri
Subject: Re: Verifying numeric values
Date: Wed, 20 Oct 2021 08:00:10 +0200

On Tue, Oct 19, 2021 at 11:15:39PM +0000, tolugboji wrote:
> 
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> 
> On Tuesday, October 19th, 2021 at 9:12 PM, Andreas Kusalananda Kähäri 
> <andreas.kahari@abc.se> wrote:
> 
> > [cut]
> >
> > > > > > if it works, I like it.
> > > > >
> > > > > Have tested [[ $x = +([[:digit:]]) ]] and it works well.
> > > > >
> > > > > There must be something happening with using +([[:digit:]])
> > > > >
> > > > > in a case statement which is not straightforward.
> > > >
> > > > Invisible case statements are the worst. Try avoiding them.
> > > >
> > > > In the meanwhile, make sure that you get the parentheses right.
> > > >
> > > > case $x in +([[:digit:]])) echo whole number; esac
> > > >
> > > > or
> > > >
> > > > case $x in (+([[:digit:]])) echo whole number; esac
> > > >
> > > > Andreas (Kusalananda) Kähäri
> > > >
> > > > SciLifeLab, NBIS, ICM
> > > >
> > > > Uppsala University, Sweden
> > >
> > > Have used the construct in a function
> > >
> > > ed-integer ()
> > >
> > > {
> > >
> > > x=300
> > >
> > > case $x in
> > >
> > > (+([[:digit:]]))
> > >
> > > echo "Integer Number"
> > >
> > > ;;
> > >
> > > esac
> > >
> > > }
> > >
> > > It works as expected. But the function seems to get called when
> > >
> > > I run the program "make" in my path, because I am getting
> > >
> > > tolu@flora:
> > >
> > > -   ~/Opstk/bld/gawk/gawk-5.1.0
> > >
> > >     make
> > >
> > >     /bin/bash: ed-integer: line 2: syntax error near unexpected token `(' 
> > > /bin/bash: ed-integer: line 2:` +([[:digit:]]))'
> > >
> > >     /bin/bash: error importing function definition for `ed-integer' 
> > > /bin/bash: ed-integer: line 2: syntax error near unexpected token` ('
> > >
> > >     /bin/bash: ed-integer: line 2: `+([[:digit:]]))' /bin/bash: error 
> > > importing function definition for`ed-integer'
> > >
> > >     make all-recursive
> > >
> > >     ...
> >
> > Yes. I can definitely see that happening under a number of possible
> > scenarios. Just make sure the extglob shell option is set prior to
> > defining the function.
> >
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------
> >
> > Andreas (Kusalananda) Kähäri
> >
> > SciLifeLab, NBIS, ICM
> >
> > Uppsala University, Sweden
> >
> > .
> 
> 
> It occurs even when using
> 
> shopt -s extglob
> 
> just after
> 
> #!/bin/bash

I can't see you script and I can't see the invocation of it.  It is
pointless to try to debug it.  Set the extglob shell option prior to
defining the function.  Don't set it in some other script.  Don't call
your script with "sh".  Don't ask for help without code that reproduces
your issue.

-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



reply via email to

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