Почему цикл while останавливается после приостановки?

Просто используйте ", а не '. Двойные кавычки допускают расширение переменных внутри кавычек, одинарные - нет.

daysAgo=1
echo $(date +%d -d "$daysAgo day ago")
06

daysAgo=1
exp="$daysAgo days ago"
echo $(date +%d -d "$exp")
06
10
27.11.2015, 01:31
1 ответ

Я написал одному из -соавторов Баша об этой проблеме, и вот его ответ:

It's not really a bug, but it is certainly a caveat.

The idea here is that you suspend processes, which are a different unit of granularity than shell commands. When a process is suspended, it returns to the shell (with a non-zero status, which has consequences when you, say, stop a process that's the loop test), which has a choice: it can break out of or continue the loop, leaving the stopped process behind. Bash chooses -- and has always chosen -- to break out of loops when a job is stopped. Continuing the loop is rarely what you want.

Some other shells do things like fork a copy of the shell when a process gets suspended due to SIGTSTP, and stop that process. Bash hasn't ever done that -- it seems more complicated than the benefit warrants -- but if someone wants to submit that code as a patch, I'd take a look at incorporating the changes.

Поэтому, если кто-то хочет отправить патч, используйте адреса электронной почты, указанные на справочных страницах.

4
20.08.2021, 12:18

Теги

Похожие вопросы