Julia语言:run()中的引号无法识别?管道错误

Cok*_*kes 1 julia

当我使用run()时,Julia忽略了引号,例如:

run(`cat file.txt | sed "s/blah/hi/"`)
Run Code Online (Sandbox Code Playgroud)

忽略引号,这是必需的.

\"
Run Code Online (Sandbox Code Playgroud)

不起作用......

编辑:错误是与管道:

cat: |: No such file or directory
cat: sed: No such file or directory
cat: s/blah/hi/: No such file or directory
ERROR: failed process: Process(`cat file.txt | sed s/blah/hi/`, ProcessExited(1)) [1]
 in pipeline_error at process.jl:502
 in run at ./process.jl:479
Run Code Online (Sandbox Code Playgroud)

Ste*_*ski 5

|不会在Julia反引号语法中创建管道.相反,您cat使用四个参数调用该程序:

  • file.txt
  • |
  • sed
  • s/blah/hi/

由于这些文件不太可能都存在,因此会cat终止并出现错误.请注意,sed最后一个参数不需要引号.事实上,如果它确实得到了引号,那么它根本不会做你想要的,因为程序将是单个字符串文字.它是看到双引号并将其内容sed作为单个参数传递的shell .在这种情况下,由于引号之间没有大多数shell特殊的空格或其他字符,因此没有区别.要完成你想要的,你可以这样做:

run(`cat file.txt` |> `sed "s/blah/hi/"`)
Run Code Online (Sandbox Code Playgroud)

双引号是可选的,因为它们在shell中,因为参数内没有空格或其他特殊字符sed.