Hot answers tagged

19

That command opened the connection on file descriptor 3. So to close the connection, you need to close file descriptor 3. To do so: exec 3<&-


11

The shell starts both, to establish the ends of the pipe, so ps sees itself as well as the process at the other end of the pipe.


4

This is impossible in general. Once an application has emitted some output, the only place where this output is stored is in the memory of the terminal. To give an extreme example, if this is the 1970s the terminal is a hardcopy printer, the output isn't getting back into the computer without somebody typing it in. If the output is still in the scrolling ...


4

You can use eval: $ set -a $ eval "$(command_that_generate_output)" $ set +a $ sh -c 'printf "%s\n" "$DATABASE_URL"' someurl


3

Your second command works, the issue is you are using bash or whatever shell that put all pipelines components in a subshell. myresult2 is properly set but the variable is immediately out of scope unless you stay in the same subshell like here: curl -L 'https://archive.org/wayback/available?url=stackoverflow.com' \ 2>/dev/null | { myresult2=$(...


3

Your command $ find . -name 'segment*' | xargs -n1 -P4 sh someFunction.sh has the effect that at most four copies of the someFunction.sh shell script will be started (-P 4) in parallel (new ones will be spawed as soon as the old ones are done), each one getting one filename as its argument (-n 1). This means that each invocation of your script will look ...


2

tr is a command that does a character-by-character translation. e.g the following command will change the character e to an E $ echo hello | tr 'e' 'E' hEllo When you use 2016-05-25 you're telling the tr command to switch the characters 2 and 0 and 1 and the range 6-0... which is where it gets confused. The command you really want to use is sed: $ sed '...


2

As @Patrick said, this problem is usually due to netcat exiting before the response has been given. You remedy that by adding -q 2 to the command line, i.e., tell netcat to hang around 2 seconds after detecting EOF on standard input. Obviously you can make it wait some other number of seconds as well.


2

Only if the terminal application was storing the raw output to a file somewhere, as e.g. iTerm does with logging enabled, or some other logging application (autoexpect(1) or equivalent) was saving the output will that raw output be available. Usually this has to be setup in advance, and requires management, e.g. if someone leaves yes running for a while then ...


2

You could use something like this assuming someFunction.sh is in your working directory. find . -name 'segment*' -print0| xargs -0 -n1 -P4 ./someFunction.sh The -print0 and -0 allow for files with spaces in the name (A common problem). In my someFunction.sh I have #!/bin/bash echo "Arg: " $1 cat $1 Which simply echo's out the file name then ...


2

The wildcard has nothing to do with grep, all that grep sees is what is piped to it. The wildcard is expanded by the shell and the list of files it expands to is passed to less. So the issue has nothing at all to do with grep. That said, if you're looking for broken links, you can do: for f in /Users/raine/.nvm/versions/node/v5.5.0/lib/node_modules/*; do ...


1

As @SatoKatsura pointed out in their comment, the (hacky) use of less is outputting to stderr, while grep reads from stdout. Though it is a poor solution to the actual task of finding dead symlinks, it can work by redirecting stderr to stdout: less ~/.nvm/versions/node/v5.5.0/lib/node_modules/* 2>&1 | grep "Not a file"


1

"But according to this logic, neither ps not less should appear in the output of ps." Yes, so your logic is wrong, because they both appear. When you run a command in a Un*x shell, very few (if any) actually run in the shell. A separate process is forked to run that command. When you pipe two commands together, both commands are launched in separate ...


1

It is not exactly "pipe", but you can basically tell scp to copy specific FD (which can be pipe) from your host to the other. Simple bash command like this: (scp does not work as it needs a size in advance): scp <(tar cz files to compress) host:/path/to/new.file but it can work with pure ssh: tar cz files to compress | ssh host "cat > /path/to/new....


1

You can't pipe output from an interactive SQLite session because it's not a shell. | doesn't do in SQL what it does on a command line. What you probably need to do is something akin to sqlite3 /path/to/mydata.sqlite "select * from todos" | grep vim, which will execute the SQL, and grep the output as you appear to be trying to do.



Only top voted, non community-wiki answers of a minimum length are eligible