stdin

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

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 the same standard input as …

Total answers: 1

Calling vim in subprocess after running cat

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 via source file This flow is useful for editing a list of files …

Total answers: 1

Stop stdin while command is running

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 type echo hello while sleep is still running observe shell as if nothing was …

Total answers: 1

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

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 following I don’t get Y in the output: $ python ask.py …

Total answers: 1

KeepassXC-cli: Send password to stdout

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 mydatabase.kdbx mymail@gmail.com end output would be the password it self. How can I achieve this ? …

Total answers: 2

Bash bind command does not work correctly for interactive commands

Bash bind command does not work correctly for interactive commands When I try bind some commands with bind -x bash utility, I can’t see my stdin input on terminal. Example: root> # bind -x ‘”C-p”: su dargod’ When I type ctrl+P – I login to user dargod, but all what I types not shows. Same …

Total answers: 1

Portable way to invoke tar with a list of files from stdin

Portable way to invoke tar with a list of files from stdin I want to create a .tgz from the content of a directory. I also want to strip the leading “./” from the tar’ed content. I had done this as follows: cd /path/to/files/ && find . -type f | cut -c 3- | xargs …

Total answers: 4

How to check if stdin is /dev/null from the shell?

How to check if stdin is /dev/null from the shell? On Linux, is there a way for a shell script to check if its standard input is redirected from the null device (1, 3) *, ideally without reading anything? The expected behavior would be: ./checkstdinnull -> no ./checkstdinnull < /dev/null -> yes echo -n | …

Total answers: 3

How does `cat`'s I/O model differ from that of other utilities?

How does `cat`'s I/O model differ from that of other utilities? From the output of stdbuf –help (GNU): Usage: stdbuf OPTION… COMMAND Run COMMAND, with modified buffering operations for its standard streams. … NOTE: If COMMAND adjusts the buffering of its standard streams (‘tee’ does for example) then that will override corresponding changes by ‘stdbuf’. …

Total answers: 2

Make tar from /dev/stdin file

Make tar from /dev/stdin file What I’m looking for is a way to pass in arbitrary data through STDIN, and have it get tar’d up as if its a normal file. I tried this $ echo test | tar -cf test.tar /dev/stdin and that gives me a test.tar file with the contents dev/stdin. The stdin …

Total answers: 3

Problems caused by STDIN set to non-blocking mode

Problems caused by STDIN set to non-blocking mode Certain commands start to consistently fail in a given terminal window: $ sudo apt-get install ipython … After this operation, 3,826 kB of additional disk space will be used. Do you want to continue? [Y/n] Abort. $ $ kinit -f <username> Password for <username>@<domain>: kinit: Pre-authentication failed: …

Total answers: 2

Communicate backwards in a pipe

Communicate backwards in a pipe I have a simple pipeline: node foo.js | node bar.js bar.js will read from stdin to get data from foo.js. But what I want to do is ensure that bar.js gets one of the last messages from foo.js before foo.js decides it’s OK to exit. Essentially I want to create …

Total answers: 3

echo or print /dev/stdin /dev/stdout /dev/stderr

echo or print /dev/stdin /dev/stdout /dev/stderr I want to print the value of /dev/stdin, /dev/stdout and /dev/stderr. Here is my simple script : #!/bin/bash echo your stdin is : $(</dev/stdin) echo your stdout is : $(</dev/stdout) echo your stderr is : $(</dev/stderr) i use the following pipes : [root@localhost home]# ls | ./myscript.sh [root@localhost home]# …

Total answers: 3

How does bash file redirection to standard in differ from shell (`sh`) on Linux?

How does bash file redirection to standard in differ from shell (`sh`) on Linux? I wrote a script which switches users while running, and executed it using file redirection to standard in. So user-switch.sh is… #!/bin/bash whoami sudo su -l root whoami And running it with bash gives me the behavior I expect $ bash …

Total answers: 2