You need to write a small Python string traversal.

In total we have 4 arguments: arg_1, arg_2, arg_3, arg_4 . They are always the same and have the format string . A string of the form is transmitted: ['arg1', 'arg2', ...] Arguments can always be different numbers - from 1 to 4, not more, but the arguments themselves are always the same and do not change values.

You need to pass all these arguments to the Bash script.

  • What does it mean to have a string format? Where does the string go? Pass arguments as, call some script with these arguments? - Flowneee
  • yes, we can call some script like this: /tmp/script.sh arg1 arg2 - Dofri
  • "Arguments can always be a different number" - where do the arguments in the Python program come from? - jfs

1 answer 1

If I understand correctly, you need to check whether there are specified arguments in the given string, and, if there is, call the script from them. If we assume that the input line is always correct, then we can do this:

 import os, re string = "['arg1', 'arg2', 'arg3', 'arg4']" # строка с аргументами script = "/tmp/script.sh" # путь к вашему скрипту os.system("{0} {1}".format(script, ' '.join(map(str, re.findall(r"\w+", string))))) # вызовет команду /tmp/script.sh arg1 arg2 arg3 arg4 в шелле и перенаправит # весь вывод в интерпретатор