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
0 answers
14 views

Why are keystrokes not intercepted after reattaching a "screen -dmS session bash -c 'command'"?

I'm using screen -dmS mysession bash -c 'command > test.txt' to start a screen, launch a command + write its stdout to a file, and detach. Later, after reattaching it with screen -r mysession, I ...
user avatar
  • 2,153
4 votes
1 answer
184 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 ...
user avatar
0 votes
1 answer
49 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:...
user avatar
  • 283
0 votes
1 answer
22 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 ...
user avatar
  • 157
0 votes
0 answers
188 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() ...
user avatar
  • 711
0 votes
1 answer
55 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 ...
user avatar
  • 115
1 vote
1 answer
100 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 ...
user avatar
  • 21
4 votes
1 answer
227 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;...
user avatar
  • 43
0 votes
0 answers
53 views

Checking/limiting incoming data from stdin

There is a sh script (dash), which I run through sudo (as root). I send him data (10 digits) via stdin. How to check/filter input stream as reliably as possible so nobody sends anything else than 10 ...
user avatar
  • 127
0 votes
1 answer
128 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 ...
user avatar
  • 3
0 votes
0 answers
29 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 ...
user avatar
  • 3
0 votes
2 answers
94 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/...
user avatar
  • 287
0 votes
1 answer
88 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 - ...
user avatar
0 votes
2 answers
588 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 -, ...
user avatar
1 vote
1 answer
387 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 && ...
user avatar
0 votes
1 answer
255 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-...
user avatar
  • 259
4 votes
2 answers
806 views

How to visualize EOF in bash

/dev/null is a special Linux file which discards everything is written to itself and which provides EOF when read. I would like to read /dev/null to obtain and visualize this EOF. If I try: $ cat /dev/...
user avatar
  • 4,503
2 votes
1 answer
110 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 ...
user avatar
  • 143
1 vote
1 answer
268 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 ...
user avatar
  • 11
0 votes
1 answer
79 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"...
user avatar
  • 1
4 votes
2 answers
248 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 ...
user avatar
  • 1,976
0 votes
0 answers
15 views

How can I do apt-get install and choose default options on screen over ssh? [duplicate]

I am trying to install linux-crashdump on Ubuntu 20.04 by sudo apt install linux-crashdump -y. However, the following options are prompted if I using ssh to login in the server first: If you choose ...
user avatar
2 votes
2 answers
182 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/...
user avatar
  • 123
0 votes
0 answers
113 views

Keeping stdin open

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 ...
user avatar
  • 8,912
1 vote
2 answers
443 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 &...
user avatar
  • 347
5 votes
1 answer
659 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 ...
user avatar
  • 613
2 votes
2 answers
1k 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 ...
user avatar
1 vote
1 answer
202 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 ...
user avatar
1 vote
1 answer
299 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 ...
user avatar
  • 111
1 vote
2 answers
211 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 ...
user avatar
  • 11
1 vote
2 answers
627 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)"
user avatar
7 votes
1 answer
600 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 ...
user avatar
  • 1,102
0 votes
1 answer
26 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 ...
user avatar
  • 115
1 vote
1 answer
232 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 |...
user avatar
1 vote
2 answers
350 views

How to pass two stdin to sudo?

My goal is to write something to a file that needs superuser privileges and I want to do it with a single line of code. Steps I have tried: I can pass a password from stdin to sudo by using its -S ...
user avatar
  • 111
0 votes
1 answer
57 views

ambiguous redirect bash from pipes

I want to delete some docker images w/ a redirection of my previouse command. docker images | grep "2 months ago" | grep -v "mailcow" | awk '{print$3}' just redirect via "&...
user avatar
  • 303
0 votes
2 answers
834 views

How to pass a block of text to python from bash

I have a block of text that I want to cat into bash and then send to python so I can work with it more. So my command line is cat input_file | sh bash_file.sh My sh file is #!/bin/sh input_data=$(cat) ...
user avatar
  • 105
0 votes
1 answer
260 views

When is podman start's `-i` needed, and how does `-i` work on podman create?

podman create has a -i flag, and without the terminal's STDIN doesn't get sent the program you run in the container, for example (don't run this) podman run -t alpine:3 /bin/sh There is no way to ...
user avatar
  • 22.8k
0 votes
2 answers
378 views

Avoid 'read' command stopping for input when no input from stdin

I have a function that takes input from the command line, and, optionally, from stdin. However, it will stop for input when no input stream is specified. #!/bin/bash somefunc() { # output strings ...
user avatar
1 vote
1 answer
450 views

Redirect script stdin to file in the background

In order to pass my script's stdin to stdin of a command in an alacritty instance it spawns, I'm trying to redirect it to a file in the background (so that the command can start reading it): t="$(...
user avatar
  • 1,608
0 votes
1 answer
643 views

command-line argument conventions for stdin, stdout

I'm writing a command-line tool that takes a file and modifies its contents. I would like the user interface to be as canonical as possible. So far, I have $ foobar -h usage: foobar [-h] [--version] [...
user avatar
4 votes
2 answers
2k views

Does `echo -n | ...` send an EOF to the pipe?

Does echo -n | ... send an EOF to the pipe? I.e., echo -n | sth Will sth recieve an EOF on its stdin?
user avatar
  • 1,295
0 votes
1 answer
80 views

Piping adb output to less behaves unpredictably

Using less to view the output of some adb commands often does not work as expected. For example hitting the spacebar to advance to the next screen often does nothing, but hitting the spacebar a second ...
user avatar
  • 279
1 vote
1 answer
384 views

Why does read appear to fail silently in my script called from another script?

Let me paint a picture for your. You write some deployment scripts or build scripts or somethings etc. which run commands on the remote to do things like e.g. create users, install/update package etc. ...
user avatar
  • 523
1 vote
2 answers
19 views

Issue with outputting to both a file and a variable in bash in one line

I would like to use $RANDOM to create the following output and write it both to a file and to a variable all in one line. 123 24234 758 4893 My attempts are as follows, and none of them worked. I ...
user avatar
  • 497
1 vote
1 answer
165 views

bruteforcing keepassxc with bash

I have forgotten part of my password to Keepassxc database (.kdbx with keyfile). The password consists of 20 symbols, 17 of which are known. I have generated the list of all possible combinations ...
user avatar
1 vote
2 answers
2k views

Best practice to read password, containing special characters like $!@`', into Bash script

I am trying to read a password from stdin into a variable in a Bash script. This variable should then be expanded into an ssh-command and transmitted to the server. There, the password should arrive ...
user avatar
  • 153
2 votes
2 answers
2k views

How does piping affect stdin?

I want to write a C program, and I need to parse stdin. If I type cat file.txt | grep -v match, how does stdout from cat resolve with -v match? Are they concatenated? Are they two different strings? I ...
user avatar
  • 129
3 votes
1 answer
3k views

How is data encoded in pipes/STDOUT/STDIN?

I have recently been looking into various text encodings and I am not able to find any good sources on how data is encoded in pipes. Here are some general assumptions I have: Pipes deal with binary, ...
user avatar
0 votes
3 answers
259 views

How to use inotifywait to call script that read from stdin

I have this code: inotifywait -m -e close_write src/lips.js ./test_port.scm | \ while read x; do ./test_port.scm; done The problem is that my script read what inotifywait produce. So my question is: ...
user avatar
  • 8,800

1
2 3 4 5 6