Project

General

Profile

Actions

action #88452

closed

script_run syntax error when & is at the end of command

Added by ph03nix about 3 years ago. Updated almost 3 years ago.

Status:
Resolved
Priority:
Low
Assignee:
Category:
Feature requests
Target version:
Start date:
2021-02-04
Due date:
2021-04-15
% Done:

0%

Estimated time:

Description

script_run and assert_script_run cause a preventable bash syntax error, when there is a '&' at the end of the command (run in background).
A solution would be to remove the ';' for the serial handling when the command terminates with ';' or '&'.

This is a (low priority) feature request to do so, to make writing tests in openQA more user friendly.

Observation

Let's assume I want to do the following

assert_script_run('sleep 30 &')

This fails with a bash syntax error, because we add the return code handling at the end of the command in the form

; echo BLABLA-$?- > /dev/serial

Which results in a command like the following:

$ sleep 30 & ; echo 12345-$?- > /dev/serial

Since '&' and ';' are terminators for bash, between the two is an empty command, which is not allowed.

Solution

If there is a terminator at the end of a script_run or assert_script_run command, omit the ';' before the echo '12345-$?- > /dev/serial'

$ sleep 30 & ; echo 12345-$?- > /dev/serial               # Syntax error
$ sleep 30 & echo 12345-$?- > /dev/serial                 # OK!

Current workarounds

I know of two possible workarounds, which are done in openQA tests:

First, enclose the command within brackets. This works but it creates a new context for the commands within the brackets, so e.g. 'jobs' or 'wait' will not work here.

assert_script_run('( sleep 30 & )');
assert_script_run('wait');         # doesn't see sleep 30 and will thus not wait for it

Second, add a true at the end of the script. This would work but most people use the first solution without being aware of the consequences. Indeed, this is the whole reason why I write this feature request :-)

assert_script_run('( sleep 30 & true');
assert_script_run('wait');         # will work
Actions

Also available in: Atom PDF