Re: Strange problem with source

2014-01-12 Thread Bert Barbe

I think what happens is the following:

"Using declare limits the scope of the variable."
Since the source of b happens inside the function includeFile, the 
declare of testVariable happens inside that function, and it's scope is 
limited to that function.


Kind regards,
Bert

On 01/12/2014 01:31 PM, Cecil Westerhof wrote:

Is this a known problem?

I have a strange problem with source. Sometimes variables are not
defined, but functions are.

I have a file a with:
 function includeFile() {
 local fileName
 local needsToExist=true

 if [[ ${1} == "--notNeeded" ]] ; then
 needsToExist=false; shift
 fi
 if [[ ${#} -ne 1 ]] ; then
 echo "includeFile [--notNeeded] "
 return 1
 fi
 INPUTFILE=${1}; shift

 if  [ -s ${INPUTFILE} -a -f ${INPUTFILE} -a -r ${INPUTFILE} ] ; then
 source ${INPUTFILE}
 else
 if [[ ${needsToExist} != false ]] ; then
 echo "${INPUTFILE} could not be used"
 return 1
 fi
 fi
 }

 includeFile b

In file b I have:
 declare testVariable="testing"
 echo ${testVariable}

 function testFunction {
 :
 }

When doing:
 source a

The string "testing" is printed and the function testFunction is
defined, but the variable testVariable is not defined.

When I change in file a the includeFile to source, testVariable is
defined.

Very strange indeed. Especially there includeFile does a source.

I am using bash 4.2.42(1)-release.






Re: problems with output redirection

2008-04-02 Thread Bert Barbe

With local and locally I mean ofcourse on the host that is running local.sh
e.g;. change local.sh to do
ssh $HOST $REMOTE_SKRIPT >>$OUTPUT
and remove the redirection to $OUTPUT in remote.sh

Bert

Bert Barbe wrote:

Interesting would be to see how the file looks like on the other hosts ;)
Maybe the file is being extended on the remote host first but the 
write() isn't synced before the local host writes again.
Why not redirect the output off ssh locally so that all writes are 
local ? That is if the output isn't huge ofcourse.

I would imagine this is more of an nfs issue than a bash issue.

Regards,
Bert

Verena Alishahi wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Dear list-members,

last week I've updated my workstation cluster client (amd 64 bit) from
SuSE 10.0 to openSUSE 10.3. My bash-version is 3.2.25(1)-release.

Now I've problems with a bash script, which I used (with bash 3.1) for
years without any problems. I really don't understand what's going on.

I've reduced my original script to a minimal script which reproduces the
output redirection error. The script works as follows:

My first script (local.sh) reads a list of worksation cluster clients
from hosts.inp in a loop and prints some output to output.txt. In the
loop a second script (remote.sh) is called in a ssh instruction.
remote.sh then writes some output to the same output.txt file, but this
output doesn't reach the output file correctly.

Both the bash-scripts and the output file are stored on an
NFS-Filesystem (on the workstation cluster server), so every client can
access them.

| less hosts.inp
client1
client2
client3
client4

| less local.sh
#!/bin/bash
OUTPUT=$HOME/bashtest/output.txt
INPUT_HOSTS=$HOME/bashtest/hosts.inp
REMOTE_SKRIPT=$HOME/bashtest/remote.sh
echo "created from $HOME/bashtest/local.sh" > $OUTPUT
for HOST in `cat $INPUT_HOSTS`
do
~  echo $HOST >> $OUTPUT
~  ssh $HOST $REMOTE_SKRIPT
~  echo "" >> $OUTPUT
done

| less remote.sh
#!/bin/bash
OUTPUT=$HOME/bashtest/output.txt
echo "TEST2" >> $OUTPUT

| less output.txt
created from /home/user1/bashtest/local.sh
client1
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@
client2
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@
client3
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@
client4
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@


Instead of all the [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@ rows, 
output.txt should contain the text
TEST2
less thinks output.txt were a binary file.
I don't understand, why the output-redirection in remote.sh doesn't
work. If I do the output-redirection in remote.sh to another file, for
example
OUTPUT2=$HOME/bashtest/output2.txt
echo "TEST2" >> $OUTPUT2
then it works.
The output-redirection only fails, when the redirection is to the same
file which is also be written from local.sh.

I appreciate receiving any help.

best regards,
Verena Alishahi
- --

Verena Alishahi

Institut für Chemie und Dynamik der Geosphäre
ICG-1: Stratosphäre
Tel.: +49 2461 61-6221
E-Mail: [EMAIL PROTECTED]

- 
-- 

- 
-- 


Forschungszentrum Jülich GmbH
52425 Jülich

Sitz der Gesellschaft: Jülich
Eingetragen im Handelsregister des Amtsgerichts Düren Nr. HR B 3498
Vorsitzende des Aufsichtsrats: MinDirig'in Bärbel Brumme-Bothe
Geschäftsführung: Prof. Dr. Achim Bachem (Vorsitzender), Dr. Ulrich 
Krafft

(stellv. Vorsitzender); Dr. Sebastian M. Schmidt
- 
-- 

- 
-- 


-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFH80XdB/rJPqfoUGARAsxsAKDW/2VyTD9vZ5hwqaBHetahrkUCTgCghVVP
6L93pwaFPbfj7O3w0IjOdSs=
=+SC6
-END PGP SIGNATURE-


---
---
Forschungszentrum Jülich GmbH
52425 Jülich

Sitz der Gesellschaft: Jülich
Eingetragen im Handelsregister des Amtsgerichts Düren Nr. HR B 3498
Vorsitzende des Aufsichtsrats: MinDir'in Bärbel Brumme-Bothe
Geschäftsführung: Prof. Dr. Achim Bachem (Vorsitzender),
Dr. Ulrich Krafft (stellv. Vorsitzender), Prof. Dr. Harald Bolt,
Dr. Sebastian M. Schmidt
---
---










Re: problems with output redirection

2008-04-02 Thread Bert Barbe

Interesting would be to see how the file looks like on the other hosts ;)
Maybe the file is being extended on the remote host first but the 
write() isn't synced before the local host writes again.
Why not redirect the output off ssh locally so that all writes are local 
? That is if the output isn't huge ofcourse.

I would imagine this is more of an nfs issue than a bash issue.

Regards,
Bert

Verena Alishahi wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Dear list-members,

last week I've updated my workstation cluster client (amd 64 bit) from
SuSE 10.0 to openSUSE 10.3. My bash-version is 3.2.25(1)-release.

Now I've problems with a bash script, which I used (with bash 3.1) for
years without any problems. I really don't understand what's going on.

I've reduced my original script to a minimal script which reproduces the
output redirection error. The script works as follows:

My first script (local.sh) reads a list of worksation cluster clients
from hosts.inp in a loop and prints some output to output.txt. In the
loop a second script (remote.sh) is called in a ssh instruction.
remote.sh then writes some output to the same output.txt file, but this
output doesn't reach the output file correctly.

Both the bash-scripts and the output file are stored on an
NFS-Filesystem (on the workstation cluster server), so every client can
access them.

| less hosts.inp
client1
client2
client3
client4

| less local.sh
#!/bin/bash
OUTPUT=$HOME/bashtest/output.txt
INPUT_HOSTS=$HOME/bashtest/hosts.inp
REMOTE_SKRIPT=$HOME/bashtest/remote.sh
echo "created from $HOME/bashtest/local.sh" > $OUTPUT
for HOST in `cat $INPUT_HOSTS`
do
~  echo $HOST >> $OUTPUT
~  ssh $HOST $REMOTE_SKRIPT
~  echo "" >> $OUTPUT
done

| less remote.sh
#!/bin/bash
OUTPUT=$HOME/bashtest/output.txt
echo "TEST2" >> $OUTPUT

| less output.txt
created from /home/user1/bashtest/local.sh
client1
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@
client2
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@
client3
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@
client4
[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@


Instead of all the [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@ rows, 
output.txt should contain the text
TEST2
less thinks output.txt were a binary file.
I don't understand, why the output-redirection in remote.sh doesn't
work. If I do the output-redirection in remote.sh to another file, for
example
OUTPUT2=$HOME/bashtest/output2.txt
echo "TEST2" >> $OUTPUT2
then it works.
The output-redirection only fails, when the redirection is to the same
file which is also be written from local.sh.

I appreciate receiving any help.

best regards,
Verena Alishahi
- --

Verena Alishahi

Institut für Chemie und Dynamik der Geosphäre
ICG-1: Stratosphäre
Tel.: +49 2461 61-6221
E-Mail: [EMAIL PROTECTED]

- 
-- 

- 
-- 


Forschungszentrum Jülich GmbH
52425 Jülich

Sitz der Gesellschaft: Jülich
Eingetragen im Handelsregister des Amtsgerichts Düren Nr. HR B 3498
Vorsitzende des Aufsichtsrats: MinDirig'in Bärbel Brumme-Bothe
Geschäftsführung: Prof. Dr. Achim Bachem (Vorsitzender), Dr. Ulrich 
Krafft

(stellv. Vorsitzender); Dr. Sebastian M. Schmidt
- 
-- 

- 
-- 


-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFH80XdB/rJPqfoUGARAsxsAKDW/2VyTD9vZ5hwqaBHetahrkUCTgCghVVP
6L93pwaFPbfj7O3w0IjOdSs=
=+SC6
-END PGP SIGNATURE-


---
---
Forschungszentrum Jülich GmbH
52425 Jülich

Sitz der Gesellschaft: Jülich
Eingetragen im Handelsregister des Amtsgerichts Düren Nr. HR B 3498
Vorsitzende des Aufsichtsrats: MinDir'in Bärbel Brumme-Bothe
Geschäftsführung: Prof. Dr. Achim Bachem (Vorsitzender),
Dr. Ulrich Krafft (stellv. Vorsitzender), Prof. Dr. Harald Bolt,
Dr. Sebastian M. Schmidt
---
---