Linked Questions
10 questions linked to/from File descriptors & shell scripting
106
votes
9
answers
72k
views
When would you use an additional file descriptor?
I know you can create a file descriptor and redirect output to it. e.g.
exec 3<> /tmp/foo # open fd 3.
echo a >&3 # write to it
exec 3>&- # close fd 3.
But you can do the same ...
111
votes
4
answers
136k
views
What does "3>&1 1>&2 2>&3" do in a script?
I saw this line in a script:
DEVICE=`dialog --inputbox "Festplatten-Laufzeit auslesen. Gebe Sie das
gewünschte Device an: " 0 70 "" 3>&1 1>&2 2>&3`
What is
3>&1 1>&...
38
votes
4
answers
52k
views
Reading lines from a file with bash: for vs. while
I'm trying to read a text file and do something with each line, using a bash script.
So, I have a list that looks like this:
server1
server2
server3
server4
I thought I could loop over this using a ...
8
votes
4
answers
13k
views
Sending the output from 'dd' to awk/sed/grep
I'm trying to approximate the computer's write speed using dd:
dd if=/dev/urandom of=/dev/null bs=1K count=10000
which gives the following output
10000+0 records in
10000+0 records out
10240000 ...
3
votes
3
answers
12k
views
Piping in awk scripts
I'm trying to write a ls wrapper that uses awk to parse the output of ls -lhF. Right now I've split the program into two files - my_ls.sh and my_ls.awk. my_ls.sh's only purpose is to pipe the output ...
4
votes
3
answers
1k
views
Why read works if stdin is redirected to fd4?
What does the following script mean?
exec 4<&0 0</etc/XX/cfg
read line1
exec 0<&4
It redirects fd0 to fd4, and "/etc/XX/cfg" to fd0.
So why does read still work, shouldn't that be ...
3
votes
3
answers
2k
views
Please help explain this bash output redirection
This script was posted as answer to a Question.
And I'm trying to work out what's going on.
result=$(
{
{
ssh host app-status >&3 3>&-; echo "$?"
} | {
until read -...
3
votes
1
answer
2k
views
Maximum time a file descriptor can be held
I am writing a long-running program in the Linux environment that will be calculating entries in a large table. Every time it comes to the end of the row, it outputs the calculated values into a ...
1
vote
1
answer
601
views
FDs more than 2, more than (stdin/stdout/sterr)
I think this post is not off-topic.We had three traditional file descriptors in Unix contexts:
0 == STDIN
1 == STDOUT
2 == STDERR
But in new articles, blogs, posts, answers, or so on, I read more ...
3
votes
2
answers
233
views
redirecting std output and std error
I have been trying to figure out the relationship between file descriptors. One thing I don't understand is, how is:
ls -l /bin/usr > ls-output.txt 2>&1
different from:
ls -l /bin/usr 2>...