Skip to main content

Questions tagged [io-redirection]

I/O redirection is used in shell scripting. This feature enables one to take the output of a command and redirect it as an input for another command, or a command can take the input from a file instead of from the standard input stream or from the terminal. The whole process helps connect data streams in various ways.

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

Interconnecting stdout and stdin between two programs [duplicate]

There are two programs first and second. I need to redirect stdout of first to stdin of second and stdout of second to stdin of first.
ibse's user avatar
  • 341
0 votes
1 answer
72 views

How to put all function/command call output results to different corresponding vars: for stderr, for stdout, for string result and for return code?

I want to extend question How to store standard error in a variable and get general solution (bash function or functions) to extract from the called function/command together with standard error also ...
Anton Samokat's user avatar
-1 votes
0 answers
40 views

The doubt about the redirection of some stdout within its transitional period

How to keep the complete stdout with its transitional period output ? As the following typical example, you can see that the yum metadata refreshing status would not be redirected to its yr.log. So ...
lylklb's user avatar
  • 303
-1 votes
1 answer
45 views

FreeBSD Reverse Shell Command Issue: Ambiguous Output Redirect Error

I’ve been experimenting with penetration testing recently, and I need to use reverse shell techniques for testing. I’ve previously used reverse shell on Ubuntu with the following command: /bin/bash -i ...
HsingLI's user avatar
  • 11
0 votes
1 answer
33 views

Run a few identical process and then kill one of them

Problem: Need to run several process, especially it will be “tail -f log.log >> wrile_log.log” proces to collect log. Commands can be run at the different time for same log file. This is not ...
Alex Alex's user avatar
0 votes
1 answer
76 views

Redirect output to file but never create empty file

Is there a way to redirect output of a command that never stops to a file but only create the file once the command actually produces output? Here is what I have so far: target=logs/$(date +%Y%m%dT%H%...
Joooeey's user avatar
  • 123
0 votes
1 answer
29 views

stdin redirection from /dev/tcp/localhost/port

I'm trying to get my head around some TCP-related topics, and have been experimenting: The following works fine: Process A: nc -l 12345 | wc -c Process B: </dev/random head -c 1k > /dev/tcp/...
k314159's user avatar
  • 447
2 votes
1 answer
100 views

bash: what's the difference between '< file' and taking input from a here-string which contains the file?

I have a variable foo_var which contains ASCII text (base64 text, with some additional text which includes dashes, spaces, and underscores). I write this var to a file as follows: cat <<<&...
QF0's user avatar
  • 305
0 votes
0 answers
30 views

Redirecting traffic from one usb port to another?

Is it possible to use a linux machine as some sort of usb passthrough? In the sense that the linux machine would act as host on one port and gadget on the other. What I am trying to achieve is to ...
Dennis Solomon's user avatar
4 votes
1 answer
270 views

pipe to a different file descriptor

Following up on Using while loop to ssh to multiple servers, i.e., for while IFS= read -r -u9 HOST ; do ssh "$HOST" "uname -a" ; done 9< servers.txt which reads from a ...
xpt's user avatar
  • 1,644
0 votes
0 answers
23 views

How to redirect after merge [duplicate]

I'm trying to get the exit code of an ls command with no other output. To do this I'm using ls /foo/bar/rak/zif/poo 2>&1 > /dev/null; echo $? But when I do this, I get a ls: cannot access /...
Yehuda's user avatar
  • 301
1 vote
3 answers
139 views

Redirecting stdout of a script as the stdin of another script/command running in a tmux session

I am adapting Marcus Müller’s answer to a question I asked last week — a script that redirects its stdout to a tmux session in order to render ANSI escape sequences, and then captures the pane render ...
Whimusical's user avatar
2 votes
3 answers
228 views

Redirection inside subshell persists after subshell closed

Without and with the dry run, the script below executes as expected for A and B, respectively. The problem arises with the dry run for A: the output is inhibited, as if 1>/dev/null persisted after ...
Erwann's user avatar
  • 667
0 votes
1 answer
62 views

Use of '&' with file descriptors [closed]

When using redirection of this form 2 > &1, why is there an '&' before 1 but not before 2?
aj31's user avatar
  • 9
1 vote
1 answer
53 views

how to catch output from a subprocess?

I am trying to catch the password prompt of sftp, but somehow it is not from STDIN or STDERR. It possibly comes from a sub-process. The following is my test. I tried to redirect the password prompt to ...
oldpride's user avatar
  • 231
0 votes
0 answers
38 views

Is it safe to redirect output of the awk command to the same file used for input? [duplicate]

In this comment, community member DannyDannyDanny asked if it is safe to redirect output of the awk command to the same file being used for input. No one answered that comment, so I would like to ...
End Antisemitic Hate's user avatar
0 votes
1 answer
50 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
51 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
50 views

Output of python script like if it's typed in interactive mode

I have a python file and I want to obtain the output just like I'm typing the content in interactive mode (like this question https://stackoverflow.com/q/59008423 but with a shell script) I try with ...
Pablo Cárdenas's user avatar
1 vote
1 answer
40 views

Bash's "set -v" doesn't echo commands within curly braces to stdout

I have the following test script: # test.bash #---------- { set -v # Echoes the following 3 parameters DELAY_MS=2000 SCALING=false VERBOSE=false set +v echo TEST TEST TEST TEST ...
user2153235's user avatar
0 votes
0 answers
32 views

How to resolve the issue of the echo (with >>) eating up the line indendations? [duplicate]

Consider the below commands typed into the terminal: $ ls my-file.js prefix.yml $ cat prefix.yml apiVersion: v1 kind: ConfigMap metadata: name: file1-cm namespace: default data: my-file.js: | $...
deostroll's user avatar
  • 317
0 votes
2 answers
40 views

Creating an option for 'exec > >(tee -ia $OUT)' to skip stdout

I'm trying to modify a script that uses the following: # first portion of script # ... exec > >(tee -ia $OUT) # ... # second portion of script The problem I have with this script is that it ...
Seamus's user avatar
  • 3,062
0 votes
0 answers
360 views

ffmpeg redirect stdout and stderr to each file and both to another in correct order

Running a simple ffmpeg command: ffmpeg -i in.avi out.mp4 -loglevel info I want the following result: stdout to both stdout.log and both.log stderr to both stderr.log and both.log The important thing ...
Smeterlink's user avatar
-1 votes
1 answer
75 views

Checking if I'm correct about the order of operations in Bash

Guten Tag! I'm a rookie in everything Bash-related. I'm familiarizing with the syntax and wanted to know if the order of operations in this command is as I thought or not. The command: echo 2 * 3 > ...
elkronequis's user avatar
0 votes
1 answer
72 views

How to redirect output to a file which name is the current date and time and current directory name?

I'm trying to redirect with current working directory in xterm. xterm -ls -geometry 80x30 -e 'cd /home/work/test1/; pwd; make | tee test1.log;' xterm -ls -geometry 80x30 -e 'cd /home/work/temp/test2/; ...
Carter's user avatar
  • 136
-1 votes
1 answer
64 views

Can you make nohup.out get created only on errors without manually specifying the file name?

Can you make nohup ./file $1 $2 & (which runs ./file in the background) create nohup.out only for errors and not for standard output? But please without manually specifying nohup.out i.e. nohup ./...
LWC's user avatar
  • 103
2 votes
1 answer
197 views

How to stop redirection via exec

I want to redirect some output of a script to a file. REDIRECT_FILE="foo.txt" echo to console # starting redirect exec > $REDIRECT_FILE echo to file echo ... echo ... # stop redirect ...
Andy A.'s user avatar
  • 207
1 vote
2 answers
204 views

Print on stdout and log with logger

I have a bash script with several "echo STRING" commands. I would like to log STRING with logger but still print it on stdout. echo STRING | logger obliviously does not do it. EDIT: echo ...
mifrey's user avatar
  • 35
0 votes
1 answer
177 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
0 answers
118 views

Log jdupes output in unRAID User Script

I have an unRAID server and I use jdupes to manage duplicate files. I set up a User Script with jdupes -rL /dir1 /dir2. However, the log of the User Script does not display the output of jdupes. ...
SvbZ3r0's user avatar
  • 111
0 votes
0 answers
17 views

Redirect \t \t output in bash [duplicate]

While doing some random thing I checked the commands using ⇥-completion (⇥⇥ on an empty prompt), it then proceeded to show me the longest paged list ever made, or so it seemed. That's when it occurred ...
Vita's user avatar
  • 311
2 votes
2 answers
175 views

tee /dev/stderr inside script truncates output file if you redirect stderr

Given a script like below if I try to redirect stderr to a file, then the file is truncated at the point tee is used: $ cat test.sh #!/bin/bash set -eux echo before echo '{ "foo": "...
Jakub Bochenski's user avatar
0 votes
1 answer
115 views

Using awk -v with Shell variable works great and prints to terminal, but when redirect to a file only the 1st record prints to the file

I am reading a file with a matching pattern then getting the first five lines after the matching pattern. The patterns are not in proper numeric order, so I am using a numeric variable in the pattern ...
Joey Simon's user avatar
0 votes
0 answers
31 views

Difference between saying "error redirected to output channel" vs "output redirected to error channel"? [duplicate]

https://community.unix.com/t/difference-between-2-1-and-2-1/392167 I was reading this post. ls name 2>&1 makes bash run ls with its stderr assigned to the same stream as its stdout (not the ...
achhainsan's user avatar
0 votes
1 answer
462 views

how to execute command and log only the command to a file

I'm trying to run a command and log only the command to a file. I've tried using exec 4>test|command >&4|exec 4>&- but doesnt' work. If I run the commands separately it works but ...
dsaizt's user avatar
  • 11
3 votes
2 answers
622 views

Piping and input stream redirection to same command, which input does command take?

I was trying to run the command given below cat numbers.txt | sort < words.txt The above command has a pipe from cat command feeding to input stream of sort command. But at the same time, input ...
Abhishek P G's user avatar
0 votes
0 answers
18 views

Why does the output in following command get written to second file rather than first file [duplicate]

I was learning about I/O redirection and tried out the following command. ls -l /bin/ > bin_contents.txt > bin_contents_copy.txt I do understand that redirection doesn't work between files. But,...
Abhishek P G's user avatar
0 votes
0 answers
48 views

Pipe or Redirect output: Linux (Remote) to Win (Local)

the following answer the question, but they're either using the HEREDOC syntax, as part of the SSH command itself, or a combination of both. @askubuntu - output-from-remote-machine-to-local-file-via-...
Sylvester DeMouser's user avatar
7 votes
1 answer
2k views

When redirecting top to a file, why does cat command on that file display output of multiple top attempts?

I am customizing a Linux system with a kernel of 6.4.0, and I have noticed a strange issue. When I execute top > a.txt and then open a window to execute cat a.txt, I find that the cat a.txt result ...
just a student's user avatar
0 votes
1 answer
210 views

When simply `| cat -`, I get file descriptor errors

Here's the working diff command: $ diff -u <(echo 'foo:bar:baz' | tr : "\n") <(echo 'foo:baz' | tr : "\n") --- /dev/fd/11 2023-08-30 13:11:50 +++ /dev/fd/13 2023-08-30 13:...
Scoobie's user avatar
  • 101
0 votes
1 answer
76 views

mkfs.xfs completely ignoring "|more" redirect

trying to install gentoo linux and can't format the drive with xfs because when I run mkfs.xfs /dev/sda3 it throws an error and then displays help, but the help is so big that it takes up the entire ...
Zack's user avatar
  • 1
2 votes
3 answers
72 views

Redirect stderr to stdout to a file in a script

I have several different algorithms, that I need to prototype. So I make prototype programs and a script. the script called time.sh looks like this echo "Timing algorithm1:" time algo1 >...
Thad_The_Man's user avatar
-1 votes
2 answers
245 views

Difference in bash 3 between pipe and here-string

If I run: IFS=':' cat <<< $(echo $PATH) then the ":" are used for word splitting and the output contains spaces instead of ":", but if I run: echo $PATH | IFS=':' cat ...
Allen's user avatar
  • 206
0 votes
0 answers
95 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
458 views

Continuously display last line of command output without clearing the screen

I want to print only the last line of the output of a command on the same line continuously without clearing the screen. This would be part of another function. Let's say my script has the following ...
blue's user avatar
  • 1
1 vote
1 answer
473 views

Permisson denied installation to USB flash

I'm trying to use basic command utilites to write ISO to USB flash. I'm writing: sudo cat path/to/archlinux-version-x86_64.iso > /dev/disk/by-id/usb-My_flash_drive but I have response: zsh: ...
S1mY's user avatar
  • 11
1 vote
0 answers
66 views

Required help with extremely hacky Bash script to view Readline's killring

I devised a contraption to visualize the killring in Bash. It work like this: $ killring Killring: 1 Line one in killring 2 Line two in killring 3 Line three in killring However, there are some ...
Sebastian Carlos's user avatar
-1 votes
1 answer
53 views

Portable temporary file descriptors inside `sh -c` [duplicate]

cat <(echo yes) Displays "yes". And running this inside sh -m results in the same thing on Bash 5.2.15. Yet on Bash 4.4.20 it throws an error: sh -c "cat <(echo yes)" sh: -c:...
Zaz's user avatar
  • 2,597
0 votes
2 answers
82 views

Why Bash redirects even when there's no command?

The Bash manual says that, after performing expansions If no command name results, redirections are performed, but do not affect the current shell environment. Now, what's a use-case for this? What'...
Sebastian Carlos's user avatar
0 votes
0 answers
26 views

Capture stderr of program into a variable without affecting stdout and interactive features [duplicate]

I have a program that asks the user for input and provides interactive features such as moving the cursor, deleting text, and more. After the user completes entering the input, the program clears the ...
sudormrfbin's user avatar

1
2 3 4 5
30