Questions tagged [stdin]

stdin is the name of the default input file descriptor of a process. Since there is really nothing special about `stdin`, you *should not* use this tag. Use the [io-redirection] tag for questions on how to redirect input, use [file-descriptors] for questions on how to manage file descriptors, use [lock] for questions of file locking, and use [files] for general questions on file operations.

Filter by
Sorted by
Tagged with
0 votes
1 answer
154 views

When and where are the standard in, out, and error file descriptors first opened in linux?

Where are stdin, stdout, and stderr (the fds) first opened? Is it the kernel that does it? And when and where are the symlinks /dev/std{in,out,err} made? Where is the code that does it? I assume it is ...
Elfen Dew's user avatar
0 votes
1 answer
110 views

Is standard streams just variables?

When I run command, e.g. test -l --hello check: shell save the command to variables, $0="test", $1="-l", $2="--hello" and $3="check" shell execute ...
linuxer's user avatar
  • 27
0 votes
0 answers
25 views

How to check if stdin have data without IO blocking (docker)?

If I execute echo this | docker run -i alpine cat, I get this. If I execute docker run -i alpine cat, I get blocked terminal, because cat reads stdin, but there is nothing there. I can check opened ...
Andrew15_5's user avatar
0 votes
0 answers
32 views

Simultaneous input from fifo and terminal in bash

I am running ffmpeg inside a script and I want to be able to quit ffmpeg either by pressing 'q' in the terminal it's running in (default behaviour) or by inputting 'q' into a fifo file, whichever I ...
Mouse'nKeyboard's user avatar
0 votes
1 answer
37 views

Calling vim in subprocess after running cat

I am trying to create a bash function vim_run which operates as follows: user pipes command output into vim_run user can edit output user exits vim and the contents of that buffer are now executed ...
zbs's user avatar
  • 3
1 vote
1 answer
54 views

Creating PKCS#12 container from input from stdin

I want to create a PKCS#12 (a.k.a PFX) container for a private key and a certificate using openssl. My key and cert are contained in a single (unecnrypted) file: $ cat d.pem -----BEGIN CERTIFICATE-----...
mat's user avatar
  • 290
0 votes
0 answers
31 views

Bash script ignores all terminal input following an underscore [duplicate]

Goal My server manages jobs using SLURM. Each job in the queue has a job ID, which can be either a single integer or two integers separated by an underscore, e.g., 123_4. You can use scontrol show job ...
Jamin's user avatar
  • 1
1 vote
2 answers
157 views

Capture and redirect stdin (user input) for runtime of script

I can redirect the stdout/stderr of everything in a script like this: #!/bin/bash exec > stdout_file echo example But now I want the stdin of the whole script to be written into a file. I tried it ...
Nudin's user avatar
  • 111
2 votes
1 answer
394 views

Stop stdin while command is running

How to stop stdin while command is running in ash (not bash)? For example: sleep 10 type echo hello while sleep is still running observe hello is in stdout after sleep finishes Desired: sleep 10 ...
wjwrpoyob's user avatar
  • 376
0 votes
1 answer
43 views

Why are commands reading from /dev/stdin get a status "[1]+ Stopped" when sent to background?

I have tried running the following commands: cat base64 /dev/stdin md5sum /dev/stdin tail /dev/stdin In all cases when I do: ^Z $ bg $ jobs I get the status: [1]+ Stopped instead of [1]+ Running. ...
Marinos An's user avatar
0 votes
3 answers
280 views

Why does < exist to redirect to stdin? [closed]

Question Why do shells implement alternative means like <<<, < <(command) and < /dev/fd/* to redirect something to stdin when pipes do exist? Example The | way (classic pipes) echo '...
Semnodime's user avatar
  • 337
0 votes
1 answer
133 views

Pipe zip & unzip together to form the identity function

Update: On closer inspection of the man page it appears that it is not yet supported by unzip to read archives from standard input. The man page refers the user to funzip instead. I guess this makes ...
Rewbert's user avatar
  • 131
5 votes
3 answers
304 views

Processing a continuous single line of data with stream processing in bash pipeline?

I am debugging an embedded server that outputs a continuous single line of text to a specified network port. There is no newline anywhere in the stream but it is text data and I would like to format ...
stmfunk's user avatar
  • 193
0 votes
1 answer
114 views

Detect whether input is coming from the terminal

I have a shell script that can read from a file or from standard input. Currently, if you don't give it a file or pipe text into it, it starts accepting input at the command prompt. Instead, I would ...
Sildoreth's user avatar
  • 1,822
1 vote
1 answer
237 views

How might I only write stdout to file if exit code is 0?

The sponge command "soak[s] up standard input and write[s] to a file", which lets us pipe from and to the same file. I want to do something similar, where I pipe to a sponge-like utility, ...
billkw's user avatar
  • 123
0 votes
0 answers
20 views

Can I safely start reading a file while it is being sent over scp?

I am copying a large sql backup to a server using scp. It takes a couple of minutes to copy. When it has finished copying, I plan to restore a database using that backup using (modulo details) mysql &...
preferred_anon's user avatar
0 votes
3 answers
240 views

save tar stdout to files using pipelines

I try to download a archive to a remote computer using SSH and also extract the archive on the remote client due to it having better performance. I have a very simple script that downloads the archive ...
Lumnezia's user avatar
  • 111
42 votes
1 answer
6k views

What's wrong with var=$(</dev/stdin) to read stdin into a variable?

We've seen a few posts here lately that use this: var=$(</dev/stdin) in an attempt to read the shell's standard input into a variable. That is however not the correct way to do it on Linux-based ...
Stéphane Chazelas's user avatar
0 votes
4 answers
206 views

Bash: interactively enter and save large html block into a variable from the terminal

This is simple #!/bin/bash echo "What is your name?" read name echo "Your name is: $name" But what if I don't want to treat a name but a large HTML code block with nested tags and ...
pastic's user avatar
  • 111
4 votes
1 answer
823 views

Why I need to type press Enter key to finish this command? [duplicate]

I'm a new Linux user and I was doing some experiments and trying to understand Process Substitution. I believe I already have a basic understanding of it. But here is a case that I don't know why. I'm ...
Fajela Tajkiya's user avatar
0 votes
1 answer
1k views

Send more than one line to an executable using bash

So python has a convenient function as part of pwntools where one can sendline() to an executable. How can I emulate this functionality in bash? Example #whatever.py x = input("First input please:...
belkarx's user avatar
  • 325
0 votes
1 answer
40 views

Text (from file) to running program

I have degenerative bone disease in my hands and would like to make YouTube videos that look like I am typing in a text editor such as Sublime or Kate (KDE). How can I make a text editor receive a ...
jwzumwalt's user avatar
  • 157
0 votes
0 answers
1k views

Bash: echo command into tty

I've a service written in Python that can receive commands and does things, here is how it is built: print("\nWelcome!\n") for line in sys.stdin: cmd=line.rstrip() ...
TCB13's user avatar
  • 721
0 votes
1 answer
99 views

How to make a list of values out of a webpage?

In this webpage there is a list of MediaWiki special pages (i.e. pages of the Special: namespace) and I wish to make a simple text list of all these names automatically. I assume that a matching ...
Lahor's user avatar
  • 113
1 vote
1 answer
376 views

Configure zsh to display my stdin in green

I wanted a simple way of displaying errors in red, and inputs in green in zsh. I found this response, that works well, but it doesn't implement the input color. I'm not really a unix developper, so I ...
Kyrela's user avatar
  • 41
4 votes
1 answer
1k views

sed: replace multi-line block with standard input

Given is input_file: 1 2 START foo END 3 Goal is to replace content inside including START ... END block with multi-line content from stdin: 1 2 hello world 3 What I tried: sed '/^START$/,/^END$/d;...
cohorte's user avatar
  • 43
1 vote
1 answer
467 views

How do I read n bytes from file descriptor 0 to a file? Bytes can be any value [duplicate]

I need to read a specific number of bytes from fd0 and write them to a file. The bytes can have any value. I assume I can't use dd since it stops at the EOF byte. Using if=/dev/stdin won't work since ...
hehehe's user avatar
  • 13
0 votes
0 answers
30 views

How does a tool like grep recognize end-of-input when reading from stdin [duplicate]

How does a tool like grep know when the end of file is reached, when reading from stdin (like in foo | grep)? The EOF byte could belong to the original file, so it can't rely on that. Does it rely on ...
hehehe's user avatar
  • 13
1 vote
2 answers
664 views

Dangers of piping to stdin of process in another terminal

Out of malicious curiosity I opened 2 terminals, each running the bash shell. In the first I type : $ echo $$ 11458 and in the second : $ echo -n "echo this command" >> /proc/11458/fd/...
db-inf's user avatar
  • 313
0 votes
1 answer
436 views

Pipe output of two commands into another script as arguments

ntopng can handle multiple network interfaces and I've a script that takes the name of the interface and outputs it in to stdout. I can pipe this output into ntopng my_packet_tracer.sh | ntopng -i - ...
khashashin's user avatar
2 votes
2 answers
3k views

wc command with no FILE argument (reading from standard input)

Regarding wc (word count) command... I am trying to understand the following (from man wc which I have quoted below plus added a longer quote at end of my question) With no FILE, or when FILE is -, ...
PurpleMongrel's user avatar
1 vote
1 answer
2k views

How to use clipboard-cli on Wayland?

I am using this module gtts-cli for text to speech conversion. more info here-> https://gtts.readthedocs.io/en/latest/cli.html Basic syntax is $ gtts-cli 'hello' --output /tmp/hello.mp3 && ...
an0nhi11's user avatar
0 votes
1 answer
795 views

stdin buffer - what is it?

While reading the "Kubernetes in Action" book I saw the following excerpt (p. 124): Listing 5.2 Enabling standard input for a container apiVersion: v1 kind: Pod metadata: name: kiada-...
mnj's user avatar
  • 271
6 votes
4 answers
2k views

How to visualize EOF in bash

/dev/null is a special Linux file which discards everything written to it, and which provides EOF when read. I would like to read /dev/null to obtain and visualize this EOF. If I try: $ cat /dev/null |...
BowPark's user avatar
  • 4,821
2 votes
1 answer
234 views

No output: busybox find . -exec sh -c ' readlink -f "$1" | tail -n +2 ' sh {} \;

I got access to only Busybox 1.31.1 I originally wanted to remove the current working directory of my output (the single dot). Example: /prueba$ ls uno dos tres When I: $ busybox find . . ./uno ./dos ...
abacox's user avatar
  • 143
2 votes
1 answer
2k views

Prompt for ssh password if needed, then pipe into the ssh session

As an experiment, I'm trying to write a script where I pipe a ZIP file into unzip on my server via ssh, however, what if I didn't have my SSH keys set up, and was prompted for a password? I'd still ...
Liran's user avatar
  • 21
0 votes
1 answer
232 views

in AIX ksh the command "mail" reads from STDIN and stops a loop wherein it is

using ksh on an AIX 7.2 system I have the following inputfile: line1 line2 line3 I have the following code (rather simplified) cat infile | while read strA ; do echo "strA: $strA"...
Rudi's user avatar
  • 1
4 votes
2 answers
343 views

In GNU screen, how to read from stdin and save into a register?

I'm using GNU screen and I want to save input from stdin into a register to slowpaste it later. I tried a workaround with a temp file (which I can read into a register with readreg afterwards) and to ...
finefoot's user avatar
  • 2,980
2 votes
2 answers
2k views

Send keypress to non-GUI program

I try to manipulate ssh process by another process. Image i run ssh root@XXXX and the pid is 12345. I want to run a program to tell the ssh session to run ls command, i tried echo ls > /proc/12345/...
demonguy's user avatar
  • 123
1 vote
1 answer
335 views

How do I keep stdin open when launching an executable via a Desktop Entry File (i.e. .desktop)?

I have a desktop application that relies on stdin. If I run it in the terminal, it runs great and quits when stdin closes (CTRL+D). I also have a systemd activation socket set up which can launch ...
Stewart's user avatar
  • 12.7k
1 vote
2 answers
1k views

Spawn a terminal and redirect its stdout to original process

I'm trying to spawn a new terminal, execute a few commands and pipe their output to stdin of the original process. A mwe of what I'm trying to do is the following bash one-liner: $ xterm -e sh -c &...
noibe's user avatar
  • 387
5 votes
1 answer
1k views

How to redirect a command's `stdin` as well as `stdout` to the output

Suppose I have the Python script: #!/usr/bin/env python input('Y/n: ') print('Next line') After I press Y, I want both the terminal and my output.txt containing: Y/n: Y Next line Running the ...
simonzack's user avatar
  • 723
8 votes
2 answers
5k views

KeepassXC-cli: Send password to stdout

I would like to authenticate to neomutt using keepassxc. I could not find a way to send password to neomutt's stdin. How can i do that ? I imagine something like this: keepassxc-cli exportpass ...
Jan Černý's user avatar
  • 1,205
1 vote
1 answer
659 views

Use piped content in a python script passed as heredoc

I am aware that here-doc goes to stdin. I saw that here-doc takes precedence in going to stdin before what's coming from the pipe (see below). But maybe there's a trick to make it work? All in all I ...
gregolsky's user avatar
1 vote
1 answer
598 views

How to access stdin/stdout from detached program?

I am trying to understand how to access stdin an stdout for a process. I have a remote machine accessible only by SSH and I want to run a terminal based program in the background. That is, I fire up ...
M.L.'s user avatar
  • 111
1 vote
2 answers
513 views

Is there any way to de-couple stdin into multiple input sources?

I am looking for a way to have two stdins to a bash script, namely one that is interactive and another which could leverage redirection Say I need to invoke a program which asks for credentials of the ...
Jorge Q's user avatar
  • 11
1 vote
2 answers
2k views

How to pipe a number into bc elegantly?

Is there a more elegant way than using xargs -Ix for the following? echo "283" | xargs -Ix bc -l -e "scale=2; l( x )/l(10)"
Jona Engel's user avatar
8 votes
1 answer
835 views

Why is the file descriptor opened and read only once?

Why can it be used only 1 time when we open the file descriptor ourselves and redirect it to stdin? Please take a look at the example below to understand what I want to say. After reading it once with ...
testter's user avatar
  • 1,310
0 votes
1 answer
30 views

What would the value of hyphen actually look like in this instance used to refer to stdin for this archive command?

I am following a guide to learn terminal commands and have encountered the use of hyphens to refer to stdin in the following command used to find all files named 'file-A' within the directory ...
nrmad's user avatar
  • 115
1 vote
1 answer
487 views

sh script, loop until stdin is closed - how can I test it?

I'm trying to pas an input stream through a pipe and want to catch a condition in which a downstream pipeline program might fail in which case I need to restart it. So I put it into a loop: step1 |...
Gunther Schadow's user avatar

1
2 3 4 5
7