1
vote
0answers
30 views

Verbose output in logfile and simple output on screen?

Let's say I have the following script: script.sh and i want the verbose output in a logfile and simple output on screen. Logfile should contain the csh -v script.sh output, and on the screen should ...
2
votes
1answer
44 views

How can I pipe the output of a program or function into a variable?

How can I pipe the output of a program or function into a variable? For example lets say I have this script: function foobarize () { sed \ -e "s|${foo}|${bar}|g" \ $1 } echo foo | ...
3
votes
2answers
38 views

Problem with read variable from AWK

I'm trying to get memory info by this command: #!/bin/bash set -x cat /proc/meminfo | grep "MemFree" | tail -n 1 | awk '{ print $2 $4 }' | read numA numB echo $numA I'm getting this + awk '{ print ...
1
vote
1answer
62 views

Why doesn't this piped script work?

#!/bin/bash rm out mkfifo out nc -l 8080 < out | while read line do echo hello > out echo $line done If I browse to the IP of the machine this script is running on (using port ...
4
votes
6answers
107 views

reading a list of lines from a file writing output to a utility

I have a file with a list of lines I want to read from another file. I want to output those lines to a utility (grep) that lets me read the entire line and pull information from it. The file with the ...
3
votes
2answers
166 views

using “ifne” in Bash pipe

In my script, I am using the ifne utility from the moreutils package. The line can be simplified to the following: printf "asdf\n" | ifne cat - && echo "stream not empty" ifne only ...
1
vote
1answer
110 views

Send copy of a script's output to a file

Say I have a Zsh script and that I would like to let it print output to STDOUT, but also copy (dump) its output to a file in disk. Moreover, the script starts with the following option set -o xtrace ...
9
votes
1answer
347 views

communication between multiple processes

I have a bash script, which runs manager() function as a separate process for x-times. How is it possible to forward messages to all manager() processes from within the script? I've read about ...
1
vote
1answer
46 views

Use a bash function in a pipelined command

I have a command similar to: ... | sort -u -V. Since some versions of sort do not support the -V flag, I thought it would be great if I made a function that conditionally adds the flag. But, it seems ...
2
votes
3answers
98 views

Script needs to read echoed line

So, I need to write a Bourne-shell script, where my script has to work with the line, that was just echoed to stdout - e.g.: echo *something* | myscript.sh [parametres...] This may be a basic ...
1
vote
1answer
50 views

observing script execution with monit script seems to ignore pipes

I want to have a bash command running in the background and being watched by monit. To get the PID of this process, I found this script on the web and I modified it to fit my commands: (named sdr.sh) ...
1
vote
2answers
147 views

Output of command when piped to another command

I am running a command which does a quick checksum of some file like so find / -type f -ctime +30 -mtime +30 -atime +30 -exec md5sum {} \; | xargs -P 4 and I am trying to run it in parallel with ...
1
vote
1answer
65 views

Best way to determine piped command to shell script?

Given tree /some/directory | print.sh Is there any way for print.sh to know that "tree -f /some/directory" was called, without trying to parse pid processes?
0
votes
2answers
151 views

bash function output to pipe [closed]

I made a bash function to beautify svn output, this function show logs one line per commit, it is great! I like it, but if I use it with pipe it does not work. You can find it on github svn-beautify ...
5
votes
3answers
402 views

How to read user input in pipe?

Let's assume I have a file named confirmation.sh with the following content: #!/bin/bash echo -n "Are you sure [Y/n]? " read line case "$line" in n|N) echo "smth" ;; y|Y) echo "smth" ...
3
votes
2answers
1k views

How to compose bash functions using pipes?

I have few functions defined in this fashion: function f { read and process $1 ... echo $result } I want to compose them together so that invocation would look like f | g | h. What idiom ...
2
votes
3answers
105 views

The processing order and printing of files with find

This simple BASH script collects msgstrs in a PHP project: #!/bin/sh TARGET=/path/to/project LPATH=locale/cy_GB/LC_MESSAGES POFILE=messages.po mkdir -p $LPATH touch $TARGET/$LPATH/$POFILE cd $TARGET ...
1
vote
3answers
98 views

Automating pipes?

I find myself using basically the same line over and over again: cat file | command1 | command2 | command3 > file Is there a way I can put all these pipes into one script, so I can just run ...
6
votes
2answers
279 views

Piping data to a process's stdin without causing EOF afterward

I have an executable that starts a user-interactive shell. I would like to, upon launch of the shell, inject a few commands first, then allow the user to have their interactive session. I can do this ...
6
votes
4answers
2k views

how do I trim each line in bash?

I would like to remove all leading and trailing spaces and tabs from each line in an output. Is there a simple tool like trim I could pipe my output into?
2
votes
3answers
203 views

How can I tell echo/printf in Bash to swallow escape codes, based on a condition?

I have a Bash script that is being run interactively and as a cron job. When run interactively it outputs colored text on the terminal. However, when run in cron it doesn't have a terminal and ...
2
votes
1answer
482 views

Linux nuisance: /dev/stdin doesn't work with sockets

Linux has this blitheringly annoying peculiarity that /dev/stdin won't work with sockets - it is hardcoded to return ENXIO. Try this: socat TCP-OPEN:localhost:1234 EXEC:cat\ /dev/stdin,nofork ...
1
vote
1answer
56 views

Pipeline each line of a file to a specific variable in a second command

I want to execute the following instruction: basex -bword=ENTRY consulta.xq But for every line of a SampleText file (plain text mainly). The SampleText contains the following lines: hello evening ...
7
votes
1answer
243 views

“w | tail” chops text at right margin (78 characters)

Summary: w | tail chops rows after 78th column. When I run the "w" command, it works as expected. However, when I pipe the output to "tail", it chops the output to 78 columns wide (truncates anything ...
0
votes
1answer
273 views

Can someone provide an xargs example piping mysql query data into another command?

Can someone provide an example for the command xargs? I want to do a mysql query to return the ID field of a column then feed that result into xargs into another command say mysql query delete. How ...
2
votes
1answer
2k views

Bash vs ksh pipes

I am stuck with some problems with my scripts in ksh. FWIW the problem which I am unable to overcome is that when I use a structure such as this command | while read VAR1 do many.commands using ...
1
vote
2answers
564 views

Print/Tee to console without passing output to pipe

Is there a way to print or tee one thing to the console and still pass something else through to the next pipe? Something like: echo dog | printOrWhatnot "PUTTING MY THING DOWN" | sed 's/dog/cat/g' | ...
0
votes
1answer
217 views

The “cp p2 &2 &” command makes Konsole to disappear, is it a bug?

The goal is start a background process that copies the data from the pipe p2 to the STDOUT as p2 is feed with data by some other process. I guess the command is incorrect. Nevertheless, the Konsole ...
8
votes
4answers
755 views

What is the easiest way to execute text from tail at the command line?

Sometimes I'm working on a new (ubuntu) box and I type git and am alerted: The program 'git' is currently not installed. You can install it by typing: apt-get install git-core If that happens I ...
3
votes
2answers
970 views

Keep global variables values piping through functions

I wrote a little bash script using sed on some html pages to extract some urls. To avoid each time grabbing sed results in a variable then read it again I simply made 3 functions and piped together. ...
2
votes
2answers
1k views

How can I retain the console input in mplayer when reading from stdin?

I'm playing around with the command line interface of mplayer. I'd like to script it in the following way find /some/path/ -type f | grep -vif blacklist | mplayer -shuffle -playlist - where ...
8
votes
2answers
2k views

Piping for loop output prevents local variable modification

I'm trying to write a simple bash function that takes, as its arguments, a number of files and/or directories. It should: Fully qualify the filenames. Sort them. Remove duplicates. Print all that ...
24
votes
3answers
1k views

Should I care about unnecessary cats?

A lot of command-line utilities can take their input either from a pipe or as a filename argument. For long shell scripts, I find starting the chain off with a cat makes it more readable, especially ...
6
votes
2answers
7k views

Why is my variable being localized in one 'while read' loop, but not in another seemingly similar loop [duplicate]

Why do I get different values for $x from the snippets below? #!/bin/bash x=1 echo fred>junk ; while read var ; do x=55 ; done <junk echo x=$x # x=55 .. I'd expect this result x=1 cat ...