Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.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中重定向输出的另一种方法_Bash_Redirect_Output - Fatal编程技术网

在Bash中重定向输出的另一种方法

在Bash中重定向输出的另一种方法,bash,redirect,output,Bash,Redirect,Output,在bash中,当我们想要读取文件时,我们使用cat命令 cat file.txt 但是如果我们不想使用空白,我们可以键入: {cat,file.txt} 有没有一种方法可以在不使用符号>或/dev/null 谢谢。|tee(称为pipe-T)-将输出(与>)重定向到文件,但也会在标准输出处打印: cat file.txt|tee outfile.txt cat file.txt|tee -a outfile.txt |tee-a:将输出附加到文件(与>>)中,但也会在标准输出处打印: cat


在bash中,当我们想要读取文件时,我们使用cat命令
cat file.txt

但是如果我们不想使用空白,我们可以键入:
{cat,file.txt}

有没有一种方法可以在不使用符号>或<或&
的情况下重定向输出 我的意思是,是否有一个与此命令等价的命令:
cat file.txt>/dev/null

谢谢。
|tee(称为pipe-T)-将输出(与>)重定向到文件,但也会在标准输出处打印:

cat file.txt|tee outfile.txt
cat file.txt|tee -a outfile.txt
|tee-a:将输出附加到文件(与>>)中,但也会在标准输出处打印:

cat file.txt|tee outfile.txt
cat file.txt|tee -a outfile.txt
|T形三通(称为pipe-T)-将输出(与>)重定向到文件,但也会在标准输出处打印:

cat file.txt|tee outfile.txt
cat file.txt|tee -a outfile.txt
|tee-a:将输出附加到文件(与>>)中,但也会在标准输出处打印:

cat file.txt|tee outfile.txt
cat file.txt|tee -a outfile.txt

除了
tee
之外,您还可以使用
exec
重定向输出

 exec 3>&1 # making file descriptor 3 to point to 1 where 1 is stdout
 exec 1>fileout #redirecting 1 ie stdout to a file
 {cat,file} # this goes to fileout & question requirement
 exec 1>&3 # restoring 1 to default
 {cat,38682813.c} # This will be printed at the stdout

除了
tee
之外,您还可以使用
exec
重定向输出

 exec 3>&1 # making file descriptor 3 to point to 1 where 1 is stdout
 exec 1>fileout #redirecting 1 ie stdout to a file
 {cat,file} # this goes to fileout & question requirement
 exec 1>&3 # restoring 1 to default
 {cat,38682813.c} # This will be printed at the stdout

我不明白你为什么想,但你可以:

eval {cat,input} "$(echo _/dev/null | tr _ '\076')"

我不明白你为什么想,但你可以:

eval {cat,input} "$(echo _/dev/null | tr _ '\076')"

... 或者
|dd of=outfile.txt
。说“在控制台上打印”是不准确的。它将数据写入命名文件以及标准输出。这可能是一个相关的tty,但通常不是。(而且它几乎肯定不是控制台。)不要将stdout与tty混为一谈。。。。或者
|dd of=outfile.txt
。说“在控制台上打印”是不准确的。它将数据写入命名文件以及标准输出。这可能是一个相关的tty,但通常不是。(而且它几乎肯定不是控制台。)不要把stdout和tty混为一谈。你为什么会关心空白?我真的无法想象你需要
{cat,file.txt}
的情况。你到底想做什么,而你不能(或不想)使用
?你为什么会关心空白?我真的无法想象你需要
{cat,file.txt}
的情况。你到底想做什么而你不能(或不想)使用
?谢谢。这就是我要找的。谢谢。这就是我要找的。