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

learn more… | top users | synonyms (1)

5
votes
2answers
826 views

How to append multiple lines to a file without last newline?

I have a very long string that is split in chunks. I want to append them to a file without putting the newline character using bash. Example: First append cat >> abc.sh << EOL echo "bla ...
4
votes
1answer
76 views

What's the difference between sh script and sh < script

What's the difference between sh myscript and sh < myscript I played around and they seem to have the same effect. Are they equivalent?
2
votes
2answers
120 views

Piping to the command substitution of a string containing pipes

This works— $ x='grep a' $ echo ab | $x ab This doesn't— $ x='grep a | grep b' $ echo ab | $x grep: |: No such file or directory grep: grep: No such file or directory grep: b: No such file or ...
1
vote
1answer
59 views

How do I redirect output from a command line app (howie AIML interpreter) to another command line app (espeak)?

I'd like to interact with an AIML interpreter that runs on the command line (Howie) using standard input and have the output played using espeak. I've tried: ./runme.py | espeak --stdin No ...
4
votes
3answers
697 views

How to output to screen overriding redirection

Is it possible, within a shell script, to write to the screen while STDOUT and STDERR is being redirected? I have a shell script that I want to capture STDOUT and STDERR. The script will run for ...
18
votes
5answers
11k views

Using while loop to ssh to multiple servers

I have a file servers.txt, with list of servers: server1.mydomain.com server2.mydomain.com server3.mydomain.com when I read the file line by line with while and echo each line, all works as ...
2
votes
2answers
116 views

Error message on terminal despite using 2> symbol

Why does this command show error message despite using 2> symbol? cat < foo 2>bar bash : cannot open foo : No such file or directory
1
vote
1answer
86 views

Crontab Triple Redirect

I have a very basic understanding of redirects, but I have come across a cronjob with redirects which I do not understand. 00 19 * * 1-5 /apps/app/scripts/doit.sh a np cron > ...
6
votes
3answers
1k views

How do you process an entire command as sudo that involves redirecting or piping?

I am trying to follow what I assume is best practises of using sudo instead of root account. I am running a simple concat file operation such as: sudo echo 'clock_hctosys="YES"' >> ...
3
votes
3answers
86 views

capture output from command without interference

How can I test whether a command's output is an empty string without interfering with said output? Example: command | ??? if [ $? = 0 ] && [ -n "$output_from_command"]; then ... I'd ...
8
votes
3answers
449 views

Why does the less-than sign not work as a replacement for cat in bash?

I heard about "useless use of cat" and found some suggestions, but the following outputs nothing in my bash shell. < filename Using cat works as expected though. cat filename I'm using Fedora ...
11
votes
2answers
206 views

Output order with process substitution

This is what I usually do to run grep and wc on a file without having to scan it twice <file.txt tee >(grep LITERAL) >(wc -l) >/dev/null However, this yields EXEC LITERAL 32 ...
4
votes
1answer
6k views

nohup: ignoring input and redirecting stderr to stdout

I am starting my application in the background using nohup as mentioned below - root@phx5qa01c:/bezook# nohup java -jar ./exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar -c file ...
3
votes
2answers
217 views

Bash if script is called from terminal echo stdout to terminal, if from cron do not echo output

I would like to have a service watchdog script echo the status to the screen if called like ./watchdog.sh but if it is run by cron, there is no need to echo output. What is the proper method? Where ...
3
votes
1answer
337 views

ProxyCommand without socat, nc or Bash's TCP redirection?

ssh_config's ProxyCommand allows to establish some connection to a proxy prior to establishing the connection to the actual target machine. Simple question: how can I leverage the dynamic or SOCKS ...
0
votes
1answer
102 views

&> redirection not working correctly

Please see the following shell transcript: $ ls input.txt test-amp-gt.sh test-both-2.sh test-both.sh test-gt.sh $ cat input.txt input file $ cat test-gt.sh #! /bin/sh cat input.txt > ...
1
vote
3answers
1k views

Line 4: $data: ambiguous redirect when using passwordbox

I want to create a passwordbox using the dialog package. #!/bin/bash data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 dialog --title "Password" \ --clear \ --passwordbox "Enter your ...
0
votes
2answers
144 views

Caveats with Stdout/Stderr Redirection to Files?

I was thinking about having the programs that start on login output their stdout/stderr to files, so I can check the stdout/stderr for any of them if necessary. I also plan to overwrite the last log ...
2
votes
1answer
177 views

What does the expression $(<“dir/file”) mean in bash?

In a bash script I cannot post here I see the following expression: $(<"dir/file") From what I understand the expression $(...) evaluates a command inside (as when using backticks), but what is ...
10
votes
4answers
233 views

How to “combine” lines printed by multiple programs safely?

Suppose I want to execute multiple programs in parallel and combine their outputs to one pipe: sh -c ' (echo qqq; echo qqq2; echo qqq3)& (echo www; echo www2; echo www3)& (echo ...
7
votes
3answers
469 views

Redirect output from all commands to file, not just last

I want to add a header to a file with echo, then use a command to create the rest of the file. This means I'll be using two separate commands. How do I write the output from both commands to a file ...
2
votes
1answer
184 views

redirect error out to standard output

I can save the error out in the same file as standard out. I have used this method below. The problem is that the error out is "always" shown at the top. In the example given below the error relates ...
2
votes
2answers
175 views

turn off buffering for `hping` in OpenBSD

It would appear that the output from hping is fully buffered when piped to perl for further line-by-line processing, so piping hping to perl doesn't work. hping --icmp-ts example.ca | perl -ne 'if ...
15
votes
2answers
536 views

How can I stream data to a program that expects to read data from a file that is given as a argument?

I have a huge gzipped file and I want a program (4s-import in this case) to read it. It takes a lot of time to first unzip the file and then call the program with the path to the file as an argument. ...
11
votes
4answers
13k views

How do I completely silence a cronjob to /dev/null/?

On my Ubuntu-Desktop and on my debian-server I have a script which needs to be executed each minute (a script that calls the minute-tic of my space online browsergame). The problem is that on ...
13
votes
2answers
451 views

What does redirection with >| do?

When should you use >| for redirecting output to a file instead of just >? The explanation given when I was shown this was that it guaranteed the target file was truncated first. But I thought ...
3
votes
1answer
2k views

What does 2>&1 in this command mean? [duplicate]

I understand that this command attempts to write to nowhere or a null device but what does 2>&1 mean here? wget -q -O - http://yourwebsite.com/wp-cron.php?doing_wp_cron > /dev/null ...
2
votes
2answers
178 views

How do I redirect only stderr?

I am having a bit of trouble doing this. I am required to run a compiled .java file and redirect only stderr to a file called error. So the .java file is named javaProgram.java. This is what I have ...
2
votes
1answer
764 views

How do I redirect all writes and reads from /sdcard/whatsapp/ to /sdcard/shared/ on android?

I am using bluestacks appplayer beta with a rooted android, I want to redirect all writes and reads from one directory to another, how do I do that? I have a terminal available to put commands in..
2
votes
2answers
270 views

What is the use of “&>>” in bash?

I was studying a bash script code where I encountered operator "&>>". I didn't understand its use. So, I referred to http://www.gnu.org/software/bash/manual/html_node/Redirections.html . It is ...
2
votes
3answers
116 views

How can a command have more than one output?

In this answer, at the very bottom, Gilles mentions that a command can have more than one output or input. Yes, there's cat foo bar | something, for having both foo and bar as inputs, and there's tee ...
2
votes
1answer
43 views

Inner logic of chained redirections

When I type cat some_file > new_file1 > new_file2 I got output from some_file in new_file2 and empty new_file1. What is the inner logic in it? More specifically what is the stdout of file? ...
3
votes
2answers
594 views

Who is file owner if the file is created using sudo command?

I logged in using my username ravbholua: ravbholua@ravbholua-Aspire-5315:~$ echo $LOGNAME ravbholua I create file named a1: ravbholua@ravbholua-Aspire-5315:~$ echo>a1 ...
1
vote
1answer
109 views

Pipe not picking up stdout

I am running a java program from a OS X 10.8 bash terminal, and are trying to rederect the output it is producing. However, when either running this throug a pipe, or rederecting it to a file, the ...
3
votes
2answers
43 views

io redirection to “cross” 2 programs

How to "cross" stdin and stdout of two programs? Specifically, I have 2 programs call pgm1 and pgm2, they are interactive tic-tac-toe games. They both output a number (0to8) indicating position where ...
4
votes
3answers
564 views

Split stdin by lines

I want to invoke a command for every line of the standard input, much like xargs, but the line should be passed as standard input, not as a command-line argument: cat some-file.txt | <magic> | ...
2
votes
1answer
169 views

input output redirection in bash [duplicate]

In Ksh for redirecting i/o from a command away from standard output/error I do , [ where command is any command that produces output/error ] command 2>filename command 2>/dev/null or command ...
7
votes
3answers
251 views

How to run a command while logging output to a file?

I have a console application that needs to be run as part of the deployment of a new application version on my server. This console application is designed to output to the console, and cannot be ...
5
votes
1answer
108 views

Replacing stdout with stderr

Is it possible to redirect the output from a command to replace the text sent to stdout with the text from stderr? $ ./script this line is redirected to stdout this line is redirected to stderr $ ...
6
votes
3answers
1k views

Restoring output to the terminal after having issued “exec &>filename”

I am trying to execute the following: exec &>filename After this I am not able to see anything including what I typed, alright. I frantically try , exec 1>&1 and exec 2>&2 , ...
0
votes
1answer
38 views

Output redirect complexities

I'm trying to have a script exit with an error in the event it can't reach an X server: xset -q &> /dev/null || { echo "The Display Server is BROKEN. Aborting."; exit 1; } However, I'm getting ...
16
votes
2answers
463 views

Why does this command create an enormously large file?

I was experimenting today with some append operations and, in my curiosity, ran this (where file1.txt was non-empty and file2.txt was empty): $ cat file1.txt >> file2.txt >> file1.txt ...
1
vote
2answers
442 views

What stream does perf use?

What stream does the perf command use!? I've been trying to capture it with (perf stat -x, -ecache-misses ./a.out>/dev/null) 2> results following http://stackoverflow.com/q/13232889/50305, ...
5
votes
1answer
75 views

Is it possible to create sticky redirection from stdout/stderr

Consider such code: echo hello >> log.txt echo world >> log.txt I execute command with stdout redirection. Is it possible to create sticky redirection? Something like this: redir ...
2
votes
1answer
116 views

Redirecting an active port

Environment: Web server that requests pages on a specific port from an application server. Problem: If a page request comes into the application server during the restart of a certain web application ...
3
votes
1answer
174 views

Pipeline and redirection understanding

Please explain this script (from ABSG. Ch. 20): exec 3>&1 # Save current "value" of stdout. ls -l 2>&1 >&3 3>&- | grep bad 3>&- # ...
13
votes
4answers
947 views

Is it possible for a sysadmin to eavesdrop on his/her users' terminals?

When logged in to a machine, I can find out each user's pseudo-terminal device(s) from the output of w. Being a sysadmin, is it possible for me to eavesdrop on this terminal without the user being ...
4
votes
2answers
651 views

What does “sh a.sh <&0 >&0” mean?

It's a question about bash shell command. "sh a.sh <&0 >&0" What dose it mean? Especially, I'm not very clear about what does &0 mean?
2
votes
1answer
136 views

xargs and < and > to the same files

I want to run git stripspace on all my source code files, on each build (or precommit or just manually), to remove extraneous whitespace, and later maybe to format the code in a standard way, So ...
10
votes
3answers
279 views

Is this a typo in Bash manual's redirection section?

Note that the order of redirections is significant. For example, the command ls > dirlist 2>&1 directs both standard output and standard error to the file dirlist, while ...