|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello, Thanks for the prompt response. I apologize if my writing was not clear. Let's try again: **************************** % ./driver.sh ./instance/env_path.cfg: line 58: EnvGGGZIP: unbound variable **************************** Such 'unbound variable' errors, like the one above, viewable ONLY on interactive shell session. I like to detect that inside a script (e.g. driver.sh) Inside driver.sh I have a line: . env_path.cfg Thanks, Farid ---------- Forwarded message ---------- Date: Wed, 16 May 2007 20:19:56 GMT From: Bill Marcum <marcumbill@bellsouth.net> Newsgroups: comp.unix.shell Subject: Re: Capturing 'unbound variable' error On Wed, 16 May 2007 12:26:49 -0600, Farid Hamjavar <hamjavar@unm.edu> wrote: > > > > Hello, > > > In bash/sh environment I use 'set -u' to catch > unset variables. > > I have: > > envcfg=${EnvRootDir}/instance/env_path.cfg > . ${envcfg} > ${errmsgs} 2>&1 > > > > Neither checking the value of $? nor redirecting > the output let me catch the 'unbound variable' error > produced by sourcing ${envcfg} > > > How do I catch the errors in above scenario? > [ -f $envcfg ] || { echo "cfg file not found" >&2; exit ; } Where will the error messages go if ${errmsgs} is not valid? Perhaps you should use a default value like ${errmsgs:-$HOME/my_errors} -- A shortcut is the longest distance between two points. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
2007-05-16, 15:56(-06), Farid Hamjavar:
[...] > % ./driver.sh > ./instance/env_path.cfg: line 58: EnvGGGZIP: unbound variable > > **************************** > > > Such 'unbound variable' errors, like the one > above, viewable ONLY on interactive shell session. > > > I like to detect that inside a script (e.g. driver.sh) > > > Inside driver.sh I have a line: > > . env_path.cfg [...] There's not much you can do. "." causes the code in the corresponding shell to be executed by the current shell process. If there's something that causes an exit there, then that exits the whole shell. You could do things like: if code=$( . env_path.cfg set export ) && eval "$code"; then echo went fine else echo did not go fine fi (untested) -- Stéphane |
|
![]() |
| Outils de la discussion | |
|
|