Tag Info

New answers tagged

0

Maybe you're using zsh. Try adding as the first line of the file, #!/usr/bin/zsh.


3

You'll want to use find's -exec option: find corpus/ -type f -exec ./individual.sh {} \; For each match that find finds, it'll execute individual.sh, replacing {} with the name of the file it found. \; is how you end an exec with find. The reason your pipe doesn't work is that the output from find is being provided to individual.sh via STDIN, not as an ...


1

The short answer is that <, >, and their variants have the highest binding precedence (tightest binding), followed by |, followed by && and ||, followed by ; and &.  So, only the echo "Thumbnail creation failed" is piped into the tee. A slightly longer answer would point out that the highest precedence is actually grouping, which can be ...


2

Your script does not have /tmp/console_test opened, the cat process does. Your script is reading from a pipe that is connected to the cat process; that's what you're seeing in your question. Search for the cat process and check that one out. You probably want something like this: while read x; do echo "received $x" eval "$x" done < ...


3

... | tee /dev/tty | ... /dev/tty is the "file" that refers to your terminal.


2

If you need to save the intermediate file after the processing is done, then inter-process communication (such as through a pipe or socket) is not particularly valuable.  Similarly, if you need to run the two programs at vastly different times, you should just do it the way you're doing it now. Back when Unix was created, disks were very small, and it was ...


2

Since the other answer isn’t being clear about this, the other (another) way is exec 3>&1 ls | sort | tee /dev/fd/3 | rev > /tmp/output The exec 3>&1 duplicates file descriptor 1 (stdout) as file descriptor 3.  Then tee /dev/fd/3 writes a copy of sort’s output to that file descriptor.  This should work in any shell, but it may be ...


4

The simplest way I can think of doing this is: ls "$@" | sort | tee >(rev > /tmp/output) The tee will send one copy to STDOUT, and since there is no longer a | after it, this is inherited, meaning it'll go to the TTY if not redirected, and your myfile if it is. The other copy will get sent to rev > /tmp/output on its STDIN. In bash, >(...) ...


-2

You can use the tee command. Here i have grouped the commands time and dd using the code block so that they will be treated as a single command and their output can be handled easily. { time dd of=$dest_filepath if=$src_filepath bs=$block_size count=$block_count; } 2>&1|tee $log_file Make note of the ; at the end of the second command. This is ...


2

What you're showing works as expected on my system. Are you sure you're using bash and not sh? In any case, I tried with dash and with busybox's sh and it worked there too. In the absence of tee, I think the only solution will be to cat $logfile after the command is finished. Another possibility would be to make a link to busybox called tee and attempt to ...


3

To quote from a very useful article wiki.bash-hackers.org: This is because the commands of the pipe run in subshells that cannot modify the parent shell. As a result, the variables of the parent shell are not modified (see article: Bash and the process tree). As the answer has been provided a few times now, an alternative way (using non builtin ...


4

It's because the part where you use the vars is a new set of commands. Use this instead: head somefile | { read A B C D E FOO; echo $A $B $C $D $E $FOO; } Also -n1 is not necessary, read only reads the first line. For better understanding this may help you, it does the same as above: read A B C D E FOO < <(head somefile); echo $A $B $C $D $E $FOO ...


0

read A B C D E FOO < <(head -n1 somefile); [... use vars here ...];


0

You can do it using reredirect (https://github.com/jerome-pouiller/reredirect/). reredirect -m /dev/null <PID> You can restore initial output of your process later using something like: reredirect -N -O <M> -E <N> <PID> (<M> and <N> are provided by previous launch of reredirect). reredirect README also explains how ...


0

You could rewrite your command using test -s /dev/stdin to check if there is any output from the mailq | grep part. - mailq | egrep 'rejected|refused' -A 5 -B 5 | mail -s 'dd' email@email + mailq | egrep 'rejected|refused' -A 5 -B 5 | (test -s /dev/stdin && cat) | mail -s 'dd' email@email


0

You may use test -s /dev/stdin (in an explicit subshell) as well. # test if a pipe is empty or not echo "string" | (test -s /dev/stdin && echo 'pipe has data' && cat || echo 'pipe is empty') echo "string" | tail -n+2 | (test -s /dev/stdin && echo 'pipe has data' && cat || echo 'pipe is empty') : | (test -s ...


2

Most commands can deal with input that's either a file that they need to open for input, or as a stream of data that's passed to the command via STDIN. When the contents of cat file.txt is sent to another command through a pipe (|) the output via STDOUT that's passed to the pipe on the left side, is setup and fed to the command that's on the right side of ...


0

If you would like to redirect the output to telnet, here is an example: ( echo "helo mailhub"; sleep 1; echo "mail from:<root>"; sleep 1; echo "rcpt to:<root>"; sleep 1; echo "data"; sleep 1; echo "[...]"; echo "."; sleep 2; ) | telnet mailserver 25 HTH


4

You don't. Use netcat nc instead. It will do what you want, whereas telnet will not. (echo helo ole.tange.dk; echo mail from: '<spam@tange.dk>'; echo rcpt to: '<spam@tange.dk>'; echo data; echo Subject: This is an email;echo;echo test;echo .;echo quit ) | nc smtp.server.example.com 25 | grep 250


2

I did a strace on both commands. The interessting thing is that when you pipe the output to head there are only 123 system calls. On the other hand when pipeing to tail there are 245 system calls (or more when there are more *.txt files). Case: head Here are the last few lines when pipeing to head: open("file12.txt", O_RDONLY) = 3 fadvise64(3, ...


2

Any process that does not block SIGPIPE will be killed if its output goes to the write end of a pipe that no one is reading from. So as soon as head closes its input (i.e. terminates), wc dies, which takes less time than finishing all the work.


0

You can do it for disappear your files: time wc -l *.txt > tee | tail But a bit you add time for tee command to time . With tee command : root@debian:/home/mohsen/test# time wc -l *.txt > tee | tail real 0m0.005s user 0m0.000s sys 0m0.000s Without tee command: root@debian:/home/mohsen/test# time wc -l *.txt | tail 8 f3.txt ...


0

I'm not sure which version of grep you are using, but if I'm reading the man page of grep correctly, then the scanning will be stopped after the first successful match. Is that what you want? What I understood from your question was that you wanted to "open all files". If you don't mind using vim or gvim, then you can use this: $ grep -n mystring *.ext ...


1

-exec takes the exit status of the command you put in it and uses it logicially within find So, just something simple like this should work find . -iname "*.ext" -exec grep -q "mystring" {} \; -exec open {} \;


3

If you have spaces in file names then you need to use print0 option for file, later -0 for xargs, and lastly -I {} for second xargs. find . -iname "*.maxpat" -print0 | xargs -0 grep -l "mystring" | xargs -I '{}' open '{}' Tested with emacs as an open command.


-1

Use pwd by find: find `pwd` -iname *.maxpat | xargs grep -l "mystring" | xargs open


2

cat F1a.txt F1b.txt | grep British | sort -d We use cat to read the contents of files on a *nix system. We then use a pipe, the character |, to feed the output from cat into grep. We then use the command grep to search the input from cat for the word British, and grep filters the output to show the proper lines. We then use another pipe to feed the output ...


0

If you want to use the directory name as-is in your script, pass it as a parameter: script $dir > outputfile You can't redirect a directory to a script, what do you expect to see as the input? The name? The names of the directory entries? The contents of the directory entries? etc. I'm assuming as you're writing scripts, you know how to process a ...


0

These are some of the tests I executed: $ vi scriptName.sh #!/bin/bash cat Then executed, $ ./scriptName < fileName It will print the contents of the file. This is a very basic example and the input is used only in one place. If you are processing the input in more than one place, which is usually the case when you write a script, then you will ...


0

You need to pass the name of the file as a parameter to the script #!/bin/bash # myscript.sh FILENAME=$1 echo "This is the filename:" $FILENAME Then this is how you will call the script ./myscript.sh thisfile.txt This will be the output for the script This is the filename: thisfile.txt


1

Commands on the right hand side of a pipe are run in a subshell - therefore, their $BASHPID is different.


1

Method #1. Using file descriptors and awk What about something like this using the solutions from this SO Q&A titled: Is there a Unix utility to prepend timestamps to lines of text? and this SO Q&A titled: pipe STDOUT and STDERR to two different processes in shell script?. The approach Step 1, we create 2 functions in Bash that will perform the ...


2

The way you tried is more or less correct. The grep pattern does not work this way. The following ways would work: egrep 'START|END' grep -E 'START|END' grep 'START\|END' parentheses around the grep call are not needed. They would start a subshell. Final command: ./run_test.sh 2>&1 | tee -a /var/log/log1.log | grep 'START\|END' > ...


2

You don't need (or want) the parentheses there. Also, the grep syntax for logical OR is grep 'foo\|bar. You need to escape the | unless you use -E. So, any of these will work: ./run_test.sh 2>&1 | tee -a log1.log | grep 'START\|END' > myscripts.log or ./run_test.sh 2>&1 | tee -a log1.log | grep -E 'START|END' > myscripts.log or ...


2

You might use coprocesses. Simple wrapper that feeds both outputs of a given command to two sed instances (one for stderr the other for stdout), which do the tagging. #!/bin/bash exec 3>&1 coproc SEDo ( sed "s/^/STDOUT: /" >&3 ) exec 4>&2- coproc SEDe ( sed "s/^/STDERR: /" >&4 ) eval $@ 2>&${SEDe[1]} 1>&${SEDo[1]} ...



Top 50 recent answers are included