2016-07-31 133 views
0


在bash當我們要讀我們使用cat命令文件的另一種方式
cat file.txt
,但如果我們不希望使用的空白,我們可以輸入:
{cat,file.txt}
有一種方法以將輸出重定向,而不使用我指的是符號>或<或&
被有等效於該命令:
cat file.txt > /dev/null
和感謝。
重定向輸出猛砸

+3

爲什麼你會在乎的空白?我無法真正描繪出你會需要'{cat,file.txt}'的情況。 – chepner

+1

你究竟在努力完成什麼,你不能(或不想)使用'>'? – chepner

回答

1

我不明白你爲什麼會想,但你可以這樣做:

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

謝謝。這就是我一直在尋找的東西。 –

3

|三通(稱爲管-T) - 將重定向輸出(同>)到文件,而且打印在標準輸出:

cat file.txt|tee outfile.txt 

|三通-a:將追加輸出到文件(同爲>>),而且打印在標準輸出:

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

...或'| dd of = outfile.txt'。 – Cyrus

+1

說「在控制檯上打印它」是不準確的。它將數據寫入指定文件以及stdout。這可能是一個相關的tty,但它通常不是。 (而且它幾乎肯定不是控制檯。)不要將stdout與tty混淆。 –

+0

@WilliamPursell謝謝 - 我更新了答案。 –

0

除了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