Skip to main content

Questions tagged [file-descriptors]

4 votes
1 answer
808 views

Why does bash need file descriptor duplicating?

I found out I don't totally understand how bash file descriptors work. I would like to have some guidance here. I have a scenario where I need to read the content of a file, and for each line of the ...
sylye's user avatar
  • 718
1 vote
1 answer
102 views

coproc redirect to stdout

Suppose I have some process that when ready will output to stdout. Even though I want my script to run asynchronously with respect to that process, I still want the script to block and wait on that ...
Mathias Sven's user avatar
5 votes
2 answers
425 views

How (internally) does fd3>&fd1 after { fd1>&fd3 } put back (or not) original fd into fd1? ("bad file descriptor")

`I'm reading an answer to https://stackoverflow.com/questions/692000/how-do-i-write-standard-error-to-a-file-while-using-tee-with-a-pipe/692009#692009, https://stackoverflow.com/a/14737103/5499118: { {...
Alex Martian's user avatar
  • 1,287
3 votes
1 answer
174 views

Bash redirections - handling several filenames specially (man pages)

Please confirm/correct me. I've found related Duplication of file descriptors in redirection but that does not answer my specific question. From the The GNU Bash Reference Manual, section 3.6 ...
Martian2020's user avatar
  • 1,483
0 votes
0 answers
62 views

I want to print debug output on failure, but ERR trap doesn't fire

I want to only print the debug output on failure, this is my attempt: #!/bin/bash set -euo pipefail dt-api() { # shellcheck disable=SC2086 curl \ --fail-with-body \ --silent \ ...
Jakub Bochenski's user avatar
0 votes
1 answer
99 views

What is (if any) the file descriptor of /dev/tty?

The urgent issue to read keyboard input in the pipeline is solved by the answer in https://stackoverflow.com/questions/15230289/read-keyboard-input-within-a-pipelined-read-loop: mycommand-outputpiped |...
Martian2020's user avatar
  • 1,483
2 votes
2 answers
507 views

what is the meaning and usage of 2>&1 | tee /dev/stderr

for the following command output=$(cat $file | docker exec -i CONTAINER COMMAND 2>&1 | tee /dev/stderr) what is the meaning and usage of 2>&1 | tee /dev/stderr? I google and 2>&...
user1169587's user avatar
7 votes
1 answer
1k views

Why does MacOS always append to a redirected file descriptor even when told to overwrite? Ubuntu only appends when strictly told to append

Given the following code: out="$(mktemp)" rm -f "$out" clear printf '%s\n' 0 >"$out" { printf '%s\n' '1' >/dev/stdout printf '%s\n' '2' >/dev/stdout } &...
balupton's user avatar
  • 644
1 vote
0 answers
81 views

How to solve uninterruptible sleep process deadlock without reboot

I have a process stuck in uninterruptible sleep. The problematic syscall is a read syscall towards /dev/fd0, which is not backed by a real floppy drive. I am trying to use modprobe and rmmod (both ...
MichaelAttard's user avatar
1 vote
1 answer
93 views

Are file permissions copied into the Open File Table?

I have a doubt on what the entry created in the Open File Table upon calling open() contains. The following schema from bytebytego seems quite good to understand the big picture of opening a file, ...
pochopsp's user avatar
  • 113
1 vote
1 answer
243 views

bash: script running in pm2 unable to access file descriptors files at /dev/fd/

I have script script.sh: #!/usr/bin/env bash # pm2 seems to always run in `bash` regardless of `#!` echo "running in $(readlink -f /proc/$$/exe)" # Redirect to both stdout(1) and stderr(2) ...
Amith's user avatar
  • 313
2 votes
1 answer
350 views

Shell/bash: Can I create a file descriptor to an existing file without emptying the file? [duplicate]

Context: I have cursory bash experience. I do not fully get file descriptors, just some basic usage. Trying to create a setup script. Most done, but a few "kinks" remain. So here is a newbie ...
mawi's user avatar
  • 23
0 votes
0 answers
30 views

How to bypass pipe detection? [duplicate]

A question at stackoverflow has answers that show the following way of detecting if standard output is a pipe: if [ -t 1 ] ; then echo terminal; else echo "not a terminal"; fi The -t flag ...
glibg10b's user avatar
  • 428
1 vote
0 answers
121 views

Is there a known linux kernel bug with two threads incorrectly getting back the same file descriptor number?

I've got a multithreaded program in which a sem_open with O_CREAT occasionally fails with EBADF. This is on an ARM linux 4.9.88, from NXP, on an embedded device. It is very difficult to reproduce, ...
Matt DiMeo's user avatar
1 vote
1 answer
837 views

Capturing output from a bash function without using a subshell [closed]

I have a bash script listening on a pipe for commands. When it sees a command it runs it. However, I would like it to support the "sideloading" of bash functions that can be called at a ...
nopcorn's user avatar
  • 9,379

15 30 50 per page
1
2 3 4 5
27