| Summary: | Определение переменной для конкретной функции перезаписывает значение глобально | ||
|---|---|---|---|
| Product: | Sisyphus | Reporter: | Vitaly Lipatov <lav> |
| Component: | sh4 | Assignee: | placeholder <placeholder> |
| Status: | NEW --- | QA Contact: | qa-sisyphus |
| Severity: | normal | ||
| Priority: | P3 | CC: | cas, evg, glebfm, iv, ldv, mike, placeholder, vt |
| Version: | unstable | ||
| Hardware: | all | ||
| OS: | Linux | ||
$ sh -c 'foo(){ echo "a=$a"; }; echo $BASH_VERSION; a=1; foo; a=2 foo; foo'
4.4.23(1)-release
a=1
a=2
a=2
$ bash -c 'foo(){ echo "a=$a"; }; echo $BASH_VERSION; a=1; foo; a=2 foo; foo'
4.4.23(1)-release
a=1
a=2
a=1
А можно узнать, какие планы по исправлению? И что делать? Искать проблему самому, переходить на использование bash? По моим сведениям, проблему вызывает использование --disable-restricted при сборке sh (В ответ на комментарий №3) > По моим сведениям, проблему вызывает использование > --disable-restricted > при сборке sh Прошу прощения, проблему вызывает отличие в названии файла: [lav@builder64 build-sh]$ md5sum sh4 bash 222e0437b72384f06b5182dec89615ac sh4 222e0437b72384f06b5182dec89615ac bash [lav@builder64 build-sh]$ ./bash -c 'foo(){ echo "a=$a"; }; echo $BASH_VERSION; a=1; foo; a=2 foo; foo' 4.4.23(1)-release a=1 a=2 a=1 [lav@builder64 build-sh]$ ./sh4 -c 'foo(){ echo "a=$a"; }; echo $BASH_VERSION; a=1; foo; a=2 foo; foo' 4.4.23(1)-release a=1 a=2 a=2 Хотелось бы отметить следующее:
$ sh3 -c 'foo(){ echo "a=$a"; }; echo $BASH_VERSION; a=1; foo; a=2 foo; foo'
3.2.57(1)-release
a=1
a=2
a=2
$ bash3 -c 'foo(){ echo "a=$a"; }; echo $BASH_VERSION; a=1; foo; a=2 foo; foo'
3.2.57(1)-release
a=1
a=2
a=1
$ dash -c 'foo(){ echo "a=$a"; }; echo $BASH_VERSION; a=1; foo; a=2 foo; foo'
a=1
a=2
a=2
$ rpm -qf `which dash`
ash-0.5.8-alt1.2e5842258.x86_64
(Ответ для Dmitry V. Levin на комментарий #1) > $ sh -c 'foo(){ echo "a=$a"; }; echo $BASH_VERSION; a=1; foo; a=2 foo; foo' > 4.4.23(1)-release > a=1 > a=2 > a=2 > > $ bash -c 'foo(){ echo "a=$a"; }; echo $BASH_VERSION; a=1; foo; a=2 foo; foo' > 4.4.23(1)-release > a=1 > a=2 > a=1 Для bash5 разницы больше нет: [lav@builder64 beeheave]$ sh -c 'foo(){ echo "a=$a"; }; echo $BASH_VERSION; a=1; foo; a=2 foo; foo' 5.2.15(1)-release a=1 a=2 a=1 [lav@builder64 beeheave]$ bash -c 'foo(){ echo "a=$a"; }; echo $BASH_VERSION; a=1; foo; a=2 foo; foo' 5.2.15(1)-release a=1 a=2 a=1 |
По неожидаемой таинственной причине переопределение переменной при вызове функции из shell переопределяет переменную глобально, если использовать sh, а не bash в качестве интерпретатора. $ ssh builder-p8 sh ./z.sh ALTLinux/p8 $ rpm -qf /bin/sh sh-3.2.57-alt1 TESTIK 1: ORIGINAL TESTIK 2: ORIGINAL TESTIK 3: REPLACED after func TESTIK 4: REPLACED after func $ ssh builder-p8 bash ./z.sh ALTLinux/p8 $ rpm -qf /bin/bash bash-3.2.57-alt1 TESTIK 1: ORIGINAL TESTIK 2: ORIGINAL TESTIK 3: REPLACED after func TESTIK 4: ORIGINAL $ ssh builder-p9 sh ./z.sh ALTLinux/p8 $ rpm -qf /bin/sh sh-4.4.23-alt1.noarch Note: /bin/sh is link to /bin/sh4 $ rpm -qf /bin/sh4 sh4-4.4.23-alt1.x86_64 TESTIK 1: ORIGINAL TESTIK 2: ORIGINAL TESTIK 3: REPLACED after func TESTIK 4: REPLACED after func $ ssh builder-p9 bash ./z.sh ALTLinux/p8 $ rpm -qf /bin/bash bash-4.4.23-alt1.noarch Note: /bin/bash is link to /bin/bash4 $ rpm -qf /bin/bash4 bash4-4.4.23-alt1.x86_64 TESTIK 1: ORIGINAL TESTIK 2: ORIGINAL TESTIK 3: REPLACED after func TESTIK 4: ORIGINAL $ ssh builder64 sh ./z.sh ALTLinux/Sisyphus $ rpm -qf /bin/sh sh-4.4.23-alt1.noarch Note: /bin/sh is link to /bin/sh4 $ rpm -qf /bin/sh4 sh4-4.4.23-alt1.x86_64 TESTIK 1: ORIGINAL TESTIK 2: ORIGINAL TESTIK 3: REPLACED after func TESTIK 4: REPLACED after func $ ssh builder64 bash ./z.sh ALTLinux/Sisyphus $ rpm -qf /bin/bash bash-4.4.23-alt1.noarch Note: /bin/bash is link to /bin/bash4 $ rpm -qf /bin/bash4 bash4-4.4.23-alt1.x86_64 TESTIK 1: ORIGINAL TESTIK 2: ORIGINAL TESTIK 3: REPLACED after func TESTIK 4: ORIGINAL $ cat z.sh #!/bin/sh test_func() { echo "TESTIK $1: $testik" } distr_info epmqf /bin/sh epmqf /bin/bash testik="ORIGINAL" test_func 1 testik='REPLACED after command' /bin/true test_func 2 testik='REPLACED after func' test_func 3 test_func 4 x