Help with C clearenv and setenv
Keith Christian
keith1christian@gmail.com
Thu May 31 03:56:00 GMT 2018
Sam,
Here is a short demonstration of how to detect unset (possibly null,
too?) variables in BASH. Not sure if this is exactly what you are
looking for but presented for info.
set -x;A_VAR="${RANDOM}";echo "1. ${A_VAR}";echo "2.
${A_VAR:?IS_NOT_SET}";unset A_VAR;set +x
+ set -x
+ A_VAR=28641
+ echo '1. 28641'
1. 28641
+ echo '2. 28641'
2. 28641
+ unset A_VAR
-bash: A_VAR: IS_NOT_SET
Documentation for is in the BASH texinfo docs, read it in a Cygwin
terminal by typing "info bash" and go to this section:
3.5.3 Shell Parameter Expansion
-------------------------------
(( lines deleted )) (( lines deleted )) (( lines deleted ))
'${PARAMETER:-WORD}'
If PARAMETER is unset or null, the expansion of WORD is
substituted. Otherwise, the value of PARAMETER is substituted.
'${PARAMETER:=WORD}'
If PARAMETER is unset or null, the expansion of WORD is assigned to
PARAMETER. The value of PARAMETER is then substituted. Positional
parameters and special parameters may not be assigned to in this
way.
'${PARAMETER:?WORD}'
If PARAMETER is null or unset, the expansion of WORD (or a message
to that effect if WORD is not present) is written to the standard
error and the shell, if it is not interactive, exits. Otherwise,
the value of PARAMETER is substituted.
'${PARAMETER:+WORD}'
If PARAMETER is null or unset, nothing is substituted, otherwise
the expansion of WORD is substituted.
(( lines deleted )) (( lines deleted )) (( lines deleted ))
Keith
On Wed, May 30, 2018 at 8:48 AM, Sam Habiel <sam.habiel@gmail.com> wrote:
> I have code for a database I am porting to Cygwin.
>
> Part of that code is a clearenv() then a couple of setenvs. There is
> an ifdef for Cygwin, as it doesn't implement clearenv. It just sets
> environ = NULL. Well--that really breaks setenv! It returns a "Bad
> Poniter" error (-1).
>
> What is the correct way to clear environment variables in Cygwin?
>
> --Sam
> (About me: http://smh101.com/)
>
> --
> Problem reports: http://cygwin.com/problems.html
> FAQ: http://cygwin.com/faq/
> Documentation: http://cygwin.com/docs.html
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
>
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
More information about the Cygwin
mailing list