Mailinglist Archive: opensuse (769 mails)

< Previous Next >
Re: [opensuse] problem with journalctl
On 05/03/2016 04:58 PM, Per Jessen wrote:
Ditto. I wasn't aware bash had such a setting.

Its not as simple as it looks;

Some commands are executed in the shell, some in a subshell.
So, whether or not VAR is exported, if we run

VAR=value echo $VAR

with or without a semicolon, it doesn't natter since the 'echo' command
is a shell built-in. We can't do a meaningful test that way.

if we think of the classical

command_one ; command_two

mode then each is executed in a subshell; BUT NOT IF THE FIRST IS A
BUILT IN COMMAND.

Setting variables is a built-in.

So, when it comes down to it, it seems that I was wrong n my first
statement.
I'm not believing that

LANG=french ; systemctl
and
LANG=french systemctl

end up being parsed & evaluated the same way because the part before the
semicolon is not run in a separate subshell and because
/etc/profile.d/lang.sh has already marked LANG for export.

Which leads me to two matters.

1. I know you can unset a variable, but I don't know can't see in the
man page, how you can "unexport".

The best I can see is save the value, unset the variable and then
recreate it;

Script started on Wed 04 May 2016 08:10:14 AM EDT
anton@Mainbox:~> export MYVAR=123
anton@Mainbox:~> echo $MYVAR
123
anton@Mainbox:~> sh
sh-4.2$ echo $MYVAR
123
sh-4.2$ exit
anton@Mainbox:~> TMP_MYVAR=$MYVAR
anton@Mainbox:~> echo $TMP_MYVAR
123
anton@Mainbox:~> sh
sh-4.2$ echo $TMP_MYVAR

sh-4.2$ exit
anton@Mainbox:~> unset MYVAR
anton@Mainbox:~> sh
sh-4.2$ echo $MYVAR

sh-4.2$ exit
anton@Mainbox:~> MYVAR=$TMP_MYVAR
anton@Mainbox:~> echo $MYVAR
123
anton@Mainbox:~> sh
sh-4.2$ echo $MYVAR

sh-4.2$ exit
anton@Mainbox:~> exit

Script done on Wed 04 May 2016 08:12:51 AM EDT


Of course some variable may be marked so that you can't unset them ...
RTFM says ...

typeset [-aAfFgilrtux] [-p] [name[=value] ...]
.....
-r Make names readonly. These names cannot then be
assigned values by subsequent assignment statements
or unset.
-x Mark names for export to subsequent commands via the
environment.



2. I can't see any simple test to see if a variable is exported.

The best I can figure is to compare the output of
"echo VAR" with that command executed in a subshell.

3. I can't tell if the 'unset' command merely unsets the value or if it
removes the variable. All the tests I can think of can't tell the
difference between an empty variable and one that doesn't exit. Perhaps
my bash-fu is lacking.



--
A: Yes.
> Q: Are you sure?
>> A: Because it reverses the logical flow of conversation.
>>> Q: Why is top posting frowned upon?

--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >