Skip to main content
The 2024 Developer Survey results are live! See the results

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
2 answers
69 views

What does '-' as a file parameter mean? [duplicate]

I'm having trouble finding a name for the - character in the context of a piped bash command. What is the - character called? Can I replace it with something more readable for a script? Example ...
tarabyte's user avatar
  • 4,376
1 vote
0 answers
61 views

Redirecting fifo to python's stdin

$ mkfifo mypipe $ echo "hello redirection" > mypipe $ cat < mypipe hello redirection I have problems when I try to do the above with python # pyecho.py with open("/dev/stdin&...
Tom Huntington's user avatar
0 votes
1 answer
46 views

Archiving stdout to multiple tapes

I have large files which are generated on the fly to stdout, one every 24hours. I would like to archive these files progressively on tapes, ideally in a single archive which potentially spans multiple ...
lorenzo's user avatar
0 votes
1 answer
52 views

Script that reads input from terminal. How to tell the script to print to both tty and stdout in case it is called with a stdout redirection?

I have a script which asks users for input in the terminal, therefore in case the script is called with stdout redirected to a file, the user has no context on the prompt. So I would like to duplicate ...
Whimusical's user avatar
0 votes
1 answer
58 views

How to identify what file descriptors are associated to STDIN, STDOUT etc

I seem to remember some command or envvar that tells you this. I'd like basically something that executed on terminal, for instance, give you echo $STDIN /dev/tty echo $STDOUT /dev/tty fdescribe 0 or ...
Whimusical's user avatar
0 votes
1 answer
52 views

Standard input stream redirection

stdin: Generally standard input, referred to as stdin, comes from the keyboard. When you type stuff, you're typing it on stdin (a standard input terminal). A standard input device, which is usually ...
Guilherme Woolley's user avatar
0 votes
0 answers
158 views

read single line from stdin and write to a file

Is there a way in bash to read a single line from stdin and write directly to a file? Something like: t="$(mktemp)" while true do [read single line from stdin] > "${t}" [...
fuumind's user avatar
  • 449
0 votes
1 answer
42 views

saving xargs ouput from multi files to one file

I have these three text files : #1.txt hey stackoverflow #2.txt hey stackexchange #3.txt hello world I am using this command to list the last 3 files in my dir and then cat them and then save ...
Anonymous101's user avatar
0 votes
1 answer
75 views

Quote characters work as commands that redirect to the standard input

I am a student and I am trying an excercise that involves assigning a word with quotes, double quotes and other symbols to a file name. The problem is that I am not getting the expected results. I am ...
Daniel's user avatar
  • 11
1 vote
1 answer
370 views

Bash - Check if the standard input contains anything

I know this question has been asked several times but it seems ineffective in my case. [[ ! -t 0 ]] = Does standard input contains anything? This command: echo 'Hello world' | [[ ! -t 0 ]] echo $? ...
Mario Palumbo's user avatar
0 votes
1 answer
375 views

How to make base64 print the encoded output after a newline without newline being encoded?

I like to encode with base64 from stdin by invoking the command pasting the input and pressing Ctrl + D twice in order to avoid a trailing newline if I don't want one to be part of the input. It ...
Kalle Richter's user avatar
0 votes
1 answer
184 views

How to pass the standard input of a shell script to a background command

In a shell script, I am trying to start a background command that has the same stdin as that of the shell script. #!/bin/sh # ... the-program & However, the-program above will not have access to ...
Flux's user avatar
  • 2,978
1 vote
1 answer
330 views

Why is stdin input replacing or corrupting my variables when running a script using SSH?

GNU bash, version 4.3.27 I'm running into an odd issue with a script that writes output to a file. The script ssh's to a list of servers and records the state/substate of a few services. I then store ...
Juts's user avatar
  • 13
0 votes
0 answers
52 views

How to regain script interactivity when `... | bash` best practices?

Let's say we have a simple script named question: #!/bin/bash read -rp "What's your name?" ans echo "Your name is $ans" Let's use cat for our example cat question | bash We ...
punkbit's user avatar
  • 111
3 votes
3 answers
828 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
136 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
1 vote
1 answer
127 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
97 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
119 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
2 votes
1 answer
336 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
  • 298
0 votes
0 answers
61 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
711 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
612 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
  • 438
0 votes
1 answer
71 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
948 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
  • 377
0 votes
1 answer
251 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
396 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
270 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,904
1 vote
1 answer
585 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
3 answers
433 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
45 votes
1 answer
10k 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
314 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
1k 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
2k 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
  • 345
0 votes
1 answer
54 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
  • 269
0 votes
0 answers
2k 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
  • 741
0 votes
1 answer
110 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
  • 123
1 vote
1 answer
474 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
2k 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
696 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
1k 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
  • 333
0 votes
1 answer
495 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
3 votes
2 answers
4k 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
964 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
  • 291
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,955
2 votes
1 answer
295 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
3k 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
316 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

1
2 3 4 5
7