New answers tagged

2

This command grep "42$" questionnaires.txt > test42 | cut -d '/' -f 1 test42 doesn't do anything like you think it does. The first part: grep "42$" questionnaires.txt > test42 That writes the output of grep to test42. The output of that is nothing. So that nothing then gets passed to cut -d '/' -f 1 test42 Which is trying to read the file you'...


0

curl https://example.com/script.sh | bash Or sudo bash if it needs to be run as root.


2

Some suggestions: Make the user put the comment in quotes, so that it is one argument: command arg1 "a long comment with many spaces" arg3 Have the comment be at the end: If user calls command arg1 arg2 a long comment with many spaces Then you can use shift to remove earlier arguments, then $* to capture all remaining: arg1="$1" #use a better name arg2="...


0

141 is the value $? gets if a process exits due to signal 13, which on Linux is SIGPIPE (see signal(7)). That's what a process gets if it tries to write to a pipe with no readers. Usually you wouldn't see that return value, since the return status of a pipe is that of the last process in it. But with pipefail set, Bash returns the last failing value. $ (...


1

Since it is bash you might consider PIPESTATUS command exit 1 | command exit 2 | command exit 3 | foobar; declare -p PIPESTATUS After the warning that foobar is not found you should get the value of PIPESTATUS declare -a PIPESTATUS=([0]="1" [1]="2" [2]="3" [3]="127")


0

Would this help? docker logs $CONTAINERID 2>&1 | cat > logfile.log


0

The definite answer is line buffering. You can demonstrate this with ping -c 3 instead of just ping, where all output is produced only at the completion of the first command. As a workaround with GNU grep you can reduce your two filters to one ping 192.168.0.1 | grep -oP '[[:digit:].]+(?= ms)' Or if you really want to use two filters, either grep --line-...


0

I think your problem is caused by the line buffering of your shell. If you let your command run long enough, you should see some output. Or just limit the amount of pings like this: $ ping -c4 192.168.0.1 | grep -o '[^ =]* ms' | grep -o '^[^ ]*' There is some more information and workarounds (solutions?) if you follow this link


1

You can create a named pipe and copy your device into that: mkfifo /tmp/mypipe cp device-file /tmp/mypipe then open another shell where you start gzip parallelly to read from the pipe and write to the output file: gzip </tmp/mypipe >outfile.gz When they are finished, you can delete the named pipe rm /tmp/mypipe


4

You can't use cp since cp would not under normal circumstances write to standard output, but you could use cat: cat device-file | gzip -c >some-output-file In this case, it makes sense to use cat since you probably need to prefix it with sudo or similar command to access the device from an unprivileged user's shell session. If you're in a root shell (...


1

Why is the occurrenceBrokenPipeError dependent on the size of what is being piped? Because writing more stuff takes more time, and the right side of the pipeline may die before your python has finished writing it. Also, if the python tries to write more than it fits in the pipe buffer, it will block and give the head -1 ample time to exit. Since the head -...


2

You could use sponge from MoreUtils: find . -type f | sponge listoffiles.txt Related: A program that could buffer stdin or file


1

The output file is created before find runs. You could create it somewhere else, say: $ find $PWD -type f > /tmp/listoffiles.txt or grep it away: $ find $PWD -type f | grep -v "^..listoffiles.txt" > /tmp/listoffiles.txt or ask find to ignore it: $ find $PWD -type f -not -name listoffiles.txt > /tmp/listoffiles.txt


1

I wrote this shell function using awk awkcliptor(){ awk -e 'BEGIN{ RS="^$" } {gsub(/^[\n\t ]*|[\n\t ]*$/,"");print ;exit}' "$1" ; } BEGIN{ RS="^$" }: in the beginning before start parsing set record separator to none i.e. treat the whole input as a single record gsub(this,that): substitute this regexp with that string /^[\n\t ]*|[\n\t ]*$/: of ...


1

Unsatisfied with the solutions presented here so far, I released the python. She was effective. This solution doesn't require setuid permissions or any actually-insane monkey-patching with shared libraries and LD_LIBRARY_PATH. Save this script somewhere in your PATH. Don't forget to chmod +x it. Suppose you save this script as pty. #!/usr/bin/env python ...


0

Too fun I know this is an old thread but I found myself in the same situ. I found out aliases are a simple workaround. At least this works for bash and fish. Not sure about all shells. Instead of: time ( foo.sh | bar.sh ) Try: alias foobar="foo.sh | bar.sh" time foobar


0

Make your first function call to destroy the fifo. You don't really care if the call fails or not. Then call mkfifo() (be sure to check the returned value to assure the operation was successful. that first call would be to unlink() Here is the syntax: #include <unistd.h> int unlink(const char *pathname); Here is the description from the MAN ...


Top 50 recent answers are included