Reputation
Next tag badge:
982/1000 score
233/200 answers
Badges
15 129 268
Newest
 vim
Impact
~3.7m people reached

7h
comment Why I should avoid loops in shells?
You've got more serious bad practises in that code like missing quotes, read without -r/IFS= or post-process the output of find (some of which are mentioned in the dup question).
7h
comment Why I should avoid loops in shells?
@Costas, that would run one bash per file and embed {} in the code is a lot worse practise than using loops. I'd still use a loop like -exec sh -c 'for script do...' sh {} + here or (GNUly): find ... -printf 'Executing %f\n' -exec {} \; -exec mv {} {}.done \; (which would run the mv only if the script succeeds).
19h
comment How to start multi-threaded grep in terminal?
Well, -n1 would start one grep per file. Unless the files are very big and there are very few of them, you'd probably want to increase that a bit as you'll spend your time starting and stopping grep processes instead of searching in files.
19h
comment find out which file descriptors share the same “open file description”
Well, that's a more intrusive variant of the heuristic approach I refer to in the question and that only works for regular files (not sockets, devices (like terminals), pipes...).
20h
comment How to start multi-threaded grep in terminal?
And unix.stackexchange.com/q/85789
20h
comment How to start multi-threaded grep in terminal?
See also unix.stackexchange.com/q/131535
20h
comment How to start multi-threaded grep in terminal?
You'd probably want to use -n in combination with -P. Otherwise, xargs may not end up spawning several processes if there are two few files.
20h
comment find out which file descriptors share the same “open file description”
Thanks. But that's not what I'm asking. On Linux, lsof does indeed use /proc/pid/fd to retrieve paths for each file descriptor and /proc/pid/fdinfo for the flags. But what I want is that for two fds to the same file whether they point to the same open file description or if the two file descriptors have been open independantly.
22h
comment Why do I receive a “/bin/bash cannot find command” error for an alias?
As I said, non-interactive bash don't expand aliases. You'd need to add a shopt -s expand_aliases to your BASH_ENV file. (you also need SHELL=/bin/bash, as vim runs the shell mentioned in there).
22h
comment Why do I receive a “/bin/bash cannot find command” error for an alias?
! spawns a shell though. However that shell is non-interactive so doesn't read customisation files like ~/.bashrc and in the case of bash doesn't expand aliases anyway.
1d
comment Search and replacing strings in a numerical data file
sed -E 's/[0-9.+-]*e[-+]?[0-9]{2}/ &/g' data.txt or sed -E 's/[0-9.+-]*e[-+]?[0-9]{2}/ &/g' < data.txt. See also sed -E 's/e[-+]?[0-9]{2}/& /g' data.txt
1d
comment Search and replacing strings in a numerical data file
Would sed -E 's/[0-9.-]*e-?[0-9]{2}/ &/g' do?
1d
comment Search and replacing strings in a numerical data file
Your expected output doesn't match your input
1d
comment echo with backspace
\b doesn't erase anything, it just writes the 0x8 character to stdout. When stdout is a terminal, that terminal understands that character as moving the cursor to the left by one column. For many terminals, that doesn't wrap, that is when the cursor is on the first column, it doesn't move back to the last column one line up. Some terminals do. Check for bw in the terminfo entry for those that do (like rxvt, Eterm...)
2d
comment What does it mean to be “sh compatible”?
Debian's posh (another pdksh derivative) may also be worth mentioning here as it's a tool to help write POSIX (well Debian policy) compliant sh scripts (where features not-specified by POSIX are being removed and cause error messages).
2d
comment What does it mean to be “sh compatible”?
Thanks for the time and effort invested in writing such a thorough answer. I just realised awarding the bounty removed the question from the featured page, I should have waited until the expiration. The SE documentation is a bit misleading on that.
2d
comment /bin/dash: check whether $1 is a number
Oh yes, sorry, I had overlooked your test for $? < 2. Still expr 9999999999999999999 + 0 gives me a 3 exit status and expr -12 + 0 and expr length + 0 give me a 0 exit status with GNU expr (+ string forces string to be considered as a string with GNU expr. expr "$a" - 0 would work better).
2d
comment /bin/dash: check whether $1 is a number
It will say that 0 is not an integer (and say -12 is which the OP's bash solution would have rejected). Some expr implementations will say that 9999999999999999999 is not an integer. POSIX gives no warranty that this will work. In practice, on a GNU system at least, it will say that "length" is an integer.
2d
comment What does it mean to be “sh compatible”?
See also the schily tools by Jörg Schilling for another port of the Bourne shell based on the OpenSolaris code.
2d
comment /bin/dash: check whether $1 is a number
It would also say that " 023 " is a number. Note that it works with dash, but not all other POSIX shells as the behaviour is unspecified if the operands are note decimal integers. For instance with ksh, it would say that SHLVL or 1+1 is a number.