Bug 45145 - Не корректная работа с переменными
Summary: Не корректная работа с переменными
Status: CLOSED NOTABUG
Alias: None
Product: Sisyphus
Classification: Development
Component: sh (show other bugs)
Version: unstable
Hardware: all Linux
: P5 critical
Assignee: Dmitry V. Levin
QA Contact: qa-sisyphus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-07 04:23 MSK by alexunderboots
Modified: 2023-04-03 10:35 MSK (History)
5 users (show)

See Also:


Attachments
info (1.01 KB, text/plain)
2023-03-23 19:06 MSK, alexunderboots
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description alexunderboots 2023-02-07 04:23:50 MSK
update, dist, kernel

#!/bin/sh
export target1='up_exp_target'
target2='up_target'
su -c "export target3='down_exp_target'
target4='down_target'
echo $target1
echo $target2
echo $target3
echo $target4" root

$target3 и 4 внутри su - не существуют. А если su -c вызывает внешний файл, то всё норм
Comment 1 alexunderboots 2023-02-07 09:14:03 MSK
Меняем кавычки
#!/bin/sh

export target1='up_exp_target'
target2='up_target'
su -c 'export target3="down_exp_target"
target4="down_target"
who
echo $target1
echo $target2
echo $target3
echo $target4' root

и вуаля - 1,3 и 4 видятся внутри su
баг переместил на интерпретатор
Comment 2 Pavel Shilov 2023-03-23 16:42:28 MSK
Прошу предоставить дополнительную информацию
* uname -a
* cat /etc/os-release
* apt-repo
Comment 3 alexunderboots 2023-03-23 19:06:47 MSK
Created attachment 12790 [details]
info
Comment 4 Pavel Shilov 2023-03-27 12:28:02 MSK
Произвел тестирование на платформе, обновленной до Sisyphus:
* p10-workstation-10.1-x86-64

Версия пакета:
* sh-4.4.23-alt1

Шаги воспроизведения:
1. создать файл скрипта проверки:
$ vim test.sh 
с текстом
#!/bin/sh
export target1='up_exp_target'
target2='up_target'
su -c "export target3='down_exp_target'
target4='down_target'
who
echo $target1
echo $target2
echo $target3
echo $target4
who" root
2. Запустить скрипт:
$ bash test.sh
3. Создать другой файл с другими кавычками:
$ vim test1.sh 
с текстом
!/bin/sh

export target1='up_exp_target'
target2='up_target'
su -c 'export target3="down_exp_target"
target4="down_target"
who
echo $target1
echo $target2
echo $target3
echo $target4' root


Фактический результат:
Вывод в терминал test1.sh 
up_exp_target

down_exp_target
down_target

Ожидаемый результат:
Вывод в терминал test1.sh 
up_exp_target
target3 и target4 выводятся от пользователя su-
Comment 5 alexunderboots 2023-04-03 06:44:33 MSK
Выполняю скрипт
#!/bin/sh
echo $pluscolor 'Настройка avachi' $nocolor
target=/etc/avahi
su -l -c "export avahidomain=$(hostname -s | cut -b 1-8)
        echo ${avahidomain}" root

В ответ получаю пустую строку
Comment 6 Dmitry V. Levin 2023-04-03 10:34:18 MSK
sh всё делает правильно, в строгом соответствии с документированной семантикой этих двух типов кавычек.
Comment 7 Dmitry V. Levin 2023-04-03 10:35:56 MSK
(In reply to Pavel Shilov from comment #2)
> Прошу предоставить дополнительную информацию
> * uname -a
> * cat /etc/os-release
> * apt-repo

Пожалуйста, такие сообщения надо закрывать, а не перевешивать.  Здесь занимаются ошибками, а не ликбезом.