2017-08-07 141 views

回答

9

您可以在規則的run塊內調用shell()多次(規則可以指定run:而非shell:):

rule processing_step: 
    input: 
     # [...] 
    output: 
     # [...] 
    run: 
     shell("somecommand {input} > tempfile") 
     shell("othercommand tempfile {output}") 

否則,由於運行塊接受Python代碼,你可以建立一個列表命令字符串和遍歷他們:

rule processing_step: 
    input: 
     # [...] 
    output: 
     # [...] 
    run: 
     commands = [ 
      "somecommand {input} > tempfile", 
      "othercommand tempfile {output}" 
     ] 
     for c in commands: 
      shell(c) 

如果沒有規則的執行過程中需要Python代碼,你可以在中使用三引號字符串塊,然後像在shell腳本中那樣編寫命令。這可以說是最可讀純殼規則:

rule processing_step: 
    input: 
     # [...] 
    output: 
     # [...] 
    shell: 
     """ 
     somecommand {input} > tempfile 
     othercommand tempfile {output} 
     """ 

如果殼命令取決於成功/前面的命令的故障時,它們可以與通常的外殼腳本運營商如||&&接合:

rule processing_step: 
    input: 
     # [...] 
    output: 
     # [...] 
    shell: 
     "command_one && echo 'command_one worked' || echo 'command_one failed'" 
+1

好,謝謝。人們在網站上展示這些例子會很有用。 – tedtoal