oils-for-unix / oils

Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!
http://www.oilshell.org/
Other
2.85k stars 159 forks source link

wait - X isn't a child of this shell process #2115

Open ale5000-git opened 3 weeks ago

ale5000-git commented 3 weeks ago

Oils 0.23.0 installed with brew install --quiet oils-for-unix.

This code works fine in almost all shells.

Code:

my_func1()
{
  echo 'Sample text'
  return 0
}

my_func2()
{
  echo 'Sample text'
  return 5
}

my_func3()
{
  echo 'Sample text'
  sleep 6
}

my_func_timeout()
{
  local _sec_limit _pid
  _sec_limit=3

  "${1}" &
  _pid="${!}"

  while test "$((_sec_limit = _sec_limit - 1))" -ge 0; do
    sleep 1
    if kill 2> /dev/null -0 "${_pid}"; then
      echo 1>&2 'Still running'
    else
      wait "${_pid}" || return "${?}"
      return '0'
    fi
  done

  kill 1>&2 "${_pid}"
  return 124
}

echo '---'
my_func_timeout 'my_func1'
echo "Return value: ${?}"
echo '---'
my_func_timeout 'my_func2'
echo "Return value: ${?}"
echo '---'
my_func_timeout 'my_func3'
echo "Return value: ${?}"
echo '---'

Instead on Oils it output:

---
Sample text
[%1] PID 3240 Done
        wait "${_pid}" || return "${?}"
             ^
/Users/runner/work/codecov-test/codecov-test/tools/bits-info.sh:32: 3240 isn't a child of this shell
Return value: 127
---
Sample text
[%1] PID 3244 Done
        wait "${_pid}" || return "${?}"
             ^
/Users/runner/work/codecov-test/codecov-test/tools/bits-info.sh:32: 3244 isn't a child of this shell
Return value: 127
---
Sample text
Still running
Still running
Still running
Return value: 124
---