| bio | website | |
|---|---|---|
| location | Seattle, WA | |
| age | 28 | |
| visits | member for | 1 year, 6 months |
| seen | May 17 at 5:21 | |
| stats | profile views | 9 |
|
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? |
|
Feb 8 |
comment |
What's a safe and portable way to split a string in shell programming? @rahmu: O.K., but be careful: IFS is often unset by default, which is not the same as being the empty string. When restoring it, you need to preserve that distinction. |
|
Feb 3 |
comment |
What's the equivalent to && when writing a bash script? @kojiro: Whoops, thanks for the correction. I see what you mean, then. :-) |
|
Feb 3 |
comment |
What's the equivalent to && when writing a bash script? Unfortunately, there are a number of standard utilities that don't follow the usual exit-status conventions, so -e can misbehave. For example, you probably don't want your script to terminate every time you diff two non-identical files. You can, of course, work around this by appending || true (or perhaps || [ $? = 1 ]) to such commands, but the OP mentions an "everyone else" who will have to read this script, and said "everyone else" will probably not be used to having to cope with -e. |
|
Feb 3 |
comment |
What's the equivalent to && when writing a bash script? @kojiro: I don't see the distinction. a && b && c will only run b if a succeeds, so "it only runs c if b succeeds" and "it only runs c if a and b both succeed" are equivalent statements: b can't succeed unless a succeeded. |
|
Nov 28 |
comment |
What's a good way to filter a text file to remove empty lines? @JosephR.: What happens is, $ can match before a newline (provided that either the /m flag is enabled, or the newline is the very last character of the string, or both), but it can also match the end of the string. For example, "abc" =~ m/^abc$/ is true. In the case of \s*$, the \s* is greedy enough to eat up the newline, and then the $ matches the end-of-string. (But I think s/^\s*\n// is clearer, anyway, so your answer is just fine as it is now.) |
|
Nov 28 |
comment |
What's a good way to filter a text file to remove empty lines? @JosephR.: The \n itself can be removed; what you can't do is remove both the $ and the \n. So s/^\s*// would have the problem you describe, but s/^\s*$// would be fine, because of the \s* and the $. (Do you see what I mean?) |
|
Nov 28 |
comment |
What's a good way to filter a text file to remove empty lines? You don't need the $, given that you have the \n. (Alternatively -- you don't need the \n, given that you have the \s* and the $; but I think s/^\s*\n// makes it clearer that the newline is removed.) You also don't need the /m; it has no effect on this command. And once you get rid of the $ and the space, you won't need the /x. |
|
Nov 13 |
awarded | Yearling |
|
Oct 27 |
comment |
Why does --text=“$@” only pass the first word? @jw013: See manatwork's comment above. His first quote, Word splitting is not performed, with the exception of "$@", comes from the explanation of the processing of the right-hand-side of variable assignments. (Just search gnu.org/software/bash/manual/bash.html for that string.) |
|
Oct 27 |
comment |
Why does --text=“$@” only pass the first word? @jw013: But according to the Bash Reference Manual, "$@" does undergo word splitting, even in variable assignments. |
|
Oct 24 |
comment |
Delete last line from the file @Rob: sed '$d' file doesn't actually modify the file; it just prints out the contents of the file, minus the last line. So sed '$d' file; sed '$d' file will print out the contents of the file twice, minus the last line each time. The delete-the-last-two-lines equivalent of sed '$d' file is sed '$d' file | sed '$d'. |
|
Oct 5 |
awarded | Commentator |
|
Oct 5 |
comment |
Why can't I redirect a path name output from one command to “cd”? Different shells, yes; but different "systems"? Are there really any shells that will support $(...) on one system but not on another?? |
|
Oct 5 |
comment |
Why can't I redirect a path name output from one command to “cd”? The OP already stated, in his/her question, that $(...) works. I don't think it's good advice to recommend backticks instead, since they have much more convoluted quoting rules and are generally more error-prone. (See §3.5.4 "Command Substitution" in the Bash Reference Manual.) |
|
Sep 21 |
comment |
How to match case insensitive patterns with ls? @mtk: To set an option, you use shopt -s; to unset it, you use shopt -u. Alternatively, you can wrap everything in a subshell by using ( ) so that the setting doesn't affect the parent shell: (shopt -s nocaseglob ; ls *abc*). |