Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash bsub命令内的输出重定向_Bash_Unix - Fatal编程技术网

Bash bsub命令内的输出重定向

Bash bsub命令内的输出重定向,bash,unix,Bash,Unix,是否可以在bsub命令内使用输出重定向,例如: bsub -q short "cat <(head -2 myfile.txt) > outputfile.txt" 然后它确实会被正确地执行(没有错误)。然而,我对实现输出重定向很感兴趣,这种重定向适用于简单的情况,但我看到人们在尝试将其应用于更复杂的脚本时遇到了很多麻烦。例如,任何使用变量或命令替换的操作都会在调用bsub(甚至bash)之前而不是之后进行扩展,这是因为在外部使用了双引号。这适用于简单的情况,但我看到人们在尝试将其

是否可以在bsub命令内使用输出重定向,例如:

bsub -q short "cat <(head -2 myfile.txt) > outputfile.txt"

然后它确实会被正确地执行(没有错误)。然而,我对实现输出重定向很感兴趣,这种重定向适用于简单的情况,但我看到人们在尝试将其应用于更复杂的脚本时遇到了很多麻烦。例如,任何使用变量或命令替换的操作都会在调用
bsub
(甚至
bash
)之前而不是之后进行扩展,这是因为在外部使用了双引号。这适用于简单的情况,但我看到人们在尝试将其应用于更复杂的脚本时遇到了很多麻烦。例如,由于外部使用双引号,任何使用变量或命令替换的内容都会在调用
bsub
(甚至
bash
)之前而不是之后进行扩展。
bsub -q short "cat \<\(head -2 myfile.txt\) > outputfile.txt"
bsub -q short "cat <\(head -2 myfile.txt\) > outputfile.txt"
bsub -q short "head -2 myfile.txt > outputfile.txt" 
bsub -q short "bash -c 'cat <(head -2 myfile.txt) > outputfile.txt'"
# for the sake of example, moving filenames out-of-band
in_file=myfile.txt
out_file=outputfile.txt

mycmd() { cat <(head -2 <"$in_file") >"$out_file"; }

export -f mycmd                # export the function into the environment
export in_file out_file        # and also any variables it uses

bsub -q short 'bash -c mycmd'  # ...before telling bsub to invoke bash to run the function