Raouf Jacker
Raouf Jacker

Reputation: 59

Another way to redirect output in Bash


in bash when we want to read file we use the cat command
cat file.txt
but if we don't want to use whitespace , we can type:
{cat,file.txt}
Is there a way to redirect output without using the symbols > or < or &
i mean is there an equivalent to this command:
cat file.txt > /dev/null
and Thanks.

Upvotes: 0

Views: 77

Answers (3)

William Pursell
William Pursell

Reputation: 212188

I don't understand why you'd want to, but you could do:

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

Upvotes: 1

Ronak Patel
Ronak Patel

Reputation: 3849

|tee (called pipe-T) - will redirect output(same as >) to file but also prints at the stdout:

cat file.txt|tee outfile.txt

|tee -a: will append output to file (same as >>) but also prints at the stdout:

cat file.txt|tee -a outfile.txt

Upvotes: 3

sjsam
sjsam

Reputation: 21955

Apart from tee You may use exec to redirect the output

 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

Upvotes: 0

Related Questions