Testing out different forms of redirections
This commit is contained in:
parent
7fca3e9ab6
commit
5d78a62a0d
3
Misc/all_normal.txt
Normal file
3
Misc/all_normal.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Everything here will be redirected to a file called all_normal
|
||||
Even this line
|
||||
And this line too
|
1
Misc/errorlog
Normal file
1
Misc/errorlog
Normal file
@ -0,0 +1 @@
|
||||
This line should go to the errorlog
|
1
Misc/file_desc3
Normal file
1
Misc/file_desc3
Normal file
@ -0,0 +1 @@
|
||||
This will go to file_desc3 file
|
54
Misc/redirections.sh
Executable file
54
Misc/redirections.sh
Executable file
@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Jack-Benny Persson
|
||||
# LX13
|
||||
# Testing diffrent forms of redirections
|
||||
|
||||
echo "This is an error message" >&2 # To redirect to a file decriptor it's must
|
||||
# be preceded by a & sign
|
||||
|
||||
echo "This is also an error message" > /dev/stderr # The same as above
|
||||
|
||||
echo "This is a normal message" >&1 # To STDOUT instead of STDERR
|
||||
|
||||
exec 1>all_normal.txt # All output below will go to a file
|
||||
# Very practical for logfiles and such
|
||||
|
||||
echo "Everything here will be redirected to a file called all_normal"
|
||||
echo "Even this line"
|
||||
echo "And this line too"
|
||||
|
||||
|
||||
exec >&2 # All output below will go to STDERR
|
||||
# Very practical for important errors and such
|
||||
|
||||
echo "But everything from here will go to STDERR"
|
||||
echo "All the errors..."
|
||||
|
||||
|
||||
exec 2>errorlog # All errors below should be redirected to a logfile
|
||||
# called errorlog
|
||||
|
||||
echo "This line should go to the errorlog" >&2
|
||||
|
||||
|
||||
exec 0< errorlog # The same can be done for input
|
||||
# Nice for processing logs etc
|
||||
|
||||
#cat # This will read from STDIN, which is now errorlog, and output will be put
|
||||
# on STDOUT... epic stuff :)
|
||||
|
||||
# This will also read from STDIN, which is now errorlog, and put it's output on
|
||||
# STDOUT togheter with line number
|
||||
Count=1
|
||||
while read Line; do
|
||||
echo "Errorlog: $Line"
|
||||
((Count++))
|
||||
done
|
||||
|
||||
# One can also create new file descriptors
|
||||
|
||||
exec 3>file_desc3
|
||||
echo "This will go to file_desc3 file" >&3
|
||||
|
||||
exit 0
|
16
Misc/redirections_reset.sh
Executable file
16
Misc/redirections_reset.sh
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Jack-Benny Persson
|
||||
# LX13
|
||||
# Testing to reset a permanent redirection
|
||||
|
||||
exec 3>&1
|
||||
exec 1>reset_test
|
||||
|
||||
echo "This line should go to the reset_test file"
|
||||
|
||||
exec 1>&3
|
||||
|
||||
echo "And this should be outputted on STDOUD as normal"
|
||||
|
||||
exit 0
|
1
Misc/reset1
Normal file
1
Misc/reset1
Normal file
@ -0,0 +1 @@
|
||||
This should go to STDOUT as usual
|
1
Misc/reset_test
Normal file
1
Misc/reset_test
Normal file
@ -0,0 +1 @@
|
||||
This line should go to the reset_test file
|
Loading…
x
Reference in New Issue
Block a user