Quote:
|
Originally Posted by lmo
true && echo $?
false || echo $?
prints 0 and 1 respectively.
growisofs || do_something
will not execute do_something if growisofs succeeds (return value $? is 0)
if growisofs fails, (return value $? will be non-zero) and procession will go (|| or) to do_something
|
Quite true - but that's a given. Basic shell eval stuff. What's the point ?
Quote:
|
Originally Posted by lmo
Just guessing
see what this does:
xterm -e 'fake || err=$? && read -p "$err" foo'
|
It doesn't do anything good, but it is quite convoluted.
A/ fake is undefined - I assume you meant somethingt else here.
B/ If fake 'fails' (returns zero) theh the second claus is executed
typically identical to "err=1". It's pointless IMO.
C/ If the second cause executed then the third must also. So we have
read -p $err foo
which is nonsense. This produces a prompt string of "1" and reads stdin
for the value of "foo" - A complete waste IMO. There is no way to
access $foo in the context of the original shell (the one that started 'xterm').
I think a lot of the folks here must really misunderstand that a shell variable
is and what context is spans.
If you create a little script like:
Quote:
[sja]# cd /tmp
[sja]# cat >mytest
#!/bin/bash
echo "FOO = $foo"
^D
[sja]# chmod +x mytest
|
Note that whenever I exectute the script "./mytest" that it creates another
bash shell as a child process.
If foo is undefined, then it is undefined in the child process;
Quote:
[sja]# echo $foo
[sja]# ./mytest
FOO =
|
If you give foo some value locally it only has that value in the current shell process, no other provcess sees it al all.
Quote:
[sja]# foo="bar"
[sja]# echo $foo
bar
[sja]# ./mytest
FOO =
|
If I export the shell valiable foo, then it is passed as an argument to child processes but it is NOT seen by any processes except child processes and their children etc ... as follows:
Quote:
[sja]# export foo="baz"
[sja]# echo $foo
baz
[sja]# ./mytest
FOO = baz
|
====
Note too that child processes CANNOT impact the shell valiables in their parent processes at all in any way; not no way, not no how - can't be done.
Quote:
[sja]# cat >mytest2
#!/bin/bash
export BLETCH="yoyoma"
echo "BLETCH = $BLETCH"
^D[sja]# chmod +x ./mytest2
[sja]# ./mytest2
BLETCH = yoyoma
|
Now try
Quote:
[sja]# BLETCH="my bletch"
[sja]# ./mytest2
BLETCH = yoyoma
[sja]# echo $BLETCH
my bletch
|
Or:
Quote:
[sja]# export BLETCH="my bletch2"
[sja]# ./mytest2
BLETCH = yoyoma
[sja]# echo $BLETCH
my bletch2
|
Sorry - but a child process (like the xterm, or a child shell) cannot pass anything to it's parents via shell or envp variables. It's one-way communication of exported shell vars(and the envp) to child processes from parents.
You need to use a file or some other IPC mechanism to pass such information since the xterm will return it's own exit code, and not that of it's child back to the original parent bash script.