[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: typeset -p on an empty integer variable is an error. (plus -v test w
From: |
John Kearney |
Subject: |
Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements) |
Date: |
Sun, 13 Jan 2013 03:31:24 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 |
Am 13.01.2013 00:04, schrieb Chet Ramey:
> On 1/12/13 10:07 AM, John Kearney wrote:
>
>> regarding -e it mainly has a bad name because there is no good guide how
>> to program with it.
>> so for example this causes stress
>> [ ! -d ${dirname} ] && mkdir ${dirname}
>> because if the dir exists it will exit the scripts :)
> I'm not sure this is what you wanted to say. When -e is set, that code
> will not cause an error exit if ${dirname} exists and is a directory. Run
> this script in the bash source directory and see what happens:
>
> set -e
> [ ! -d builtins ] && mkdir builtins
> echo after
>
>
> Chet
:)
its a little more complex, truthfully I make rules how I should do stuff
and then just follow them.
in this case you actually need to put the code in a function, then its
actually the function return not the command itself that causes the
exit. At least I think thats what happens, truthfully sometimes even
with the caller trace it can be hard to tell what is actually going on.
i.e.
set -o errexit
test_func() {
[ ! -d test ] && echo test2
}
echo test3
test_func
echo test4
now so long as test doesn't exist in the cwd it should errexit.
at least it did for me just now.
Like I say the only reason I don't like errexit is it doesn't say why it
exited, so I use the ERR trap. Which is great.
Just to clarify I'm not complaining just saying why I think ppl have bad
experiences with errexit.
having said that it might be nice to get an optional backtrace on
errors. I do this myself but it might help others if it was natively
supported.
John
- typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), Dan Douglas, 2013/01/11
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), John Kearney, 2013/01/11
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), Dan Douglas, 2013/01/11
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), John Kearney, 2013/01/11
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), Dan Douglas, 2013/01/12
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), John Kearney, 2013/01/12
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), Chet Ramey, 2013/01/12
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements),
John Kearney <=
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), Greg Wooledge, 2013/01/14
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), John Kearney, 2013/01/14
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), Greg Wooledge, 2013/01/14
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), John Kearney, 2013/01/14
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), Chet Ramey, 2013/01/14
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), John Kearney, 2013/01/15
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), Ken Irving, 2013/01/14
- Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), John Kearney, 2013/01/14
Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements), Chet Ramey, 2013/01/11