PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Re: Capturing 'unbound variable' error (fwd)
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Re: Capturing 'unbound variable' error (fwd)

Réponse
 
LinkBack Outils de la discussion
Vieux 16/05/2007, 22h56   #1
Farid Hamjavar
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Capturing 'unbound variable' error (fwd)


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.
  Réponse avec citation
Vieux 18/05/2007, 15h47   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Capturing 'unbound variable' error (fwd)

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07673 seconds with 10 queries