203 reputation
25
bio website
location Seattle, WA
age 29
visits member for 2 years, 11 months
seen Oct 18 at 17:50

Aug
4
comment Is space not allowed in a filename?
@terdon: That's not really true. $'\0' is equivalent to '' -- and (for example) $'foo\0bar' is equivalent to foo. You may prefer to write $'\0' instead of '' when the notation better matches the semantics you have in mind, but don't let it deceive you.
Jun
16
awarded  Caucus
Jun
16
awarded  Constituent
Oct
26
comment Pipe to multiple files in the shell
+1. This is the most generally-applicable answer, since it doesn't depend on the fact that the specific filtering command was grep.
Oct
22
comment Why does while [ 0 ] go into infinite loop?
Re: "When it isn't given an expression that looks like a comparison, file test, or one of the other operations it can do, it simply succeeds": I don't think that's a good way to put it. After all, [ ] (with no argument) and [ "" ] (with a single empty argument) do not succeed.
Oct
7
comment How to display the number of lines output by a command in real time?
+1, though to be absolutely correct, you should change read to read -r (since otherwise a backslash at the end of a line would mess with the counting). Incidentally, with a bit of work, this can be adapted to also show the latest line of output, which may be useful for some commands.
Sep
22
comment What is the name of the shell feature `>(tee copyError.txt >&2)`?
The first half of this answer is wrong, or at least highly misleading; it's true that > can denote output-redirection and that () can denote a subshell, but >(...) is actually a single, unitary feature that does not consist of > and ().
Sep
19
comment What exactly is an environment variable?
Some of this is not quite right. For example, subshells are subprocesses and must be fork()ed, but they do receive (copies of) shell variables.
Aug
18
comment Unix: how to read line's original content from file
+1. I'd also recommend setting IFS to the null string, so that leading whitespace is not discarded, and specifying the -r flag to read, so that backslashes are not processed/discarded. That is: instead of while read line, I'd recommend writing while IFS= read -r line. It's more verbose, but it guarantees that no mangling will happen. (Unless the line contains null bytes . . .)
Aug
10
comment bash equivalent of zsh's $@[2,$#]
(In other words, yes: your Bash function works, and is probably what the OP wants, and +1. Stephane Chazelas is just pointing out a case where zsh behaves differently, and is taking the OP's request for an "equivalent" rather strictly.)
Aug
10
comment bash equivalent of zsh's $@[2,$#]
@slm: What Stephane Chazelas is saying is that in zsh's $@[2,$#], empty arguments will disappear. In Bash as in zsh, the only way to get empty arguments to disappear is to leave $@ unquoted; but in Bash unlike in zsh, that will have other effects, such as filename expansion and word splitting. If you want to disable those effects, you have to set IFS to the empty string (disabling word splitting) and run set -f (disabling filename expansion); but once you do that, although $@ will still expand to all arguments, ${@:2} will expand to a string with all arguments concatenated.
Jul
22
comment How to chmod without /usr/bin/chmod?
@goldilocks: Interesting! The Single Unix Specification does mark cc as "LEGACY" (and therefore optional), but I didn't realize that Linux distros were actually taking it up on that. :-P (Of course, it doesn't list perl at all, even as an optional utility.)
Jul
22
comment How to chmod without /usr/bin/chmod?
@goldilocks: I didn't mean "as opposed to Python" (since you didn't mention Python); I meant "as opposed to C"!
Jul
21
comment How to chmod without /usr/bin/chmod?
Re: "most linux distros require the [perl interpreter] to work": Really? Can you elaborate a bit on that?
Jun
26
comment How to get the lines that contain -R with grep
+1 for encouraging creativity. There is more than one way to do it!
May
16
comment Can sed remove 'double' newline characters?
For the first Perl one, you should actually set $/ to "" (which is a magic value for just this sort of purpose).
Feb
22
awarded  Editor
Feb
22
revised Why is printf better than echo?
avoid use of "echo" to mean specifically "a certain version of echo that is not the one found in Bash and various other shells"
Feb
22
suggested suggested edit on Why is printf better than echo?
Feb
11
comment Iterate over multiple parameters with spaces in bash script
But what if the filenames contain newlines?