Using SED with wildcard
The asterisk (*) means “zero or more of the previous item”. If you want to match any single character use If you want to match any string (i.e. any single character zero or more times) use
The asterisk (*) means “zero or more of the previous item”. If you want to match any single character use If you want to match any string (i.e. any single character zero or more times) use
Bash does not support multidimensional arrays, nor hashes, and it seems that you want a hash that values are arrays. This solution is not very beautiful, a solution with an xml file should be better : EDIT: this answer is quite old, since since bash 4 supports hash tables, see also this answer for a solution without … Read more
Updated answer (Jan 2020) xargs is now the recommended tool to achieve parallel execution. It’s pre-installed almost everywhere. For running multiple rsync tasks the command would be: This will list all folders in /srv/mail, pipe them to xargs, which will read them one-by-one and and run 4 rsync processes at a time. The % char replaces the input argument for each command call. Original … Read more
Multiprocessing
You can use the key option of the sort command, which takes a “field number”, so if you wanted the second column: -n, –numeric-sort compare according to string numerical value For example:
Here’s how to do it with the # and % operators in Bash. ${x%.bar} could also be ${x%.*} to remove everything after a dot or ${x%%.*} to remove everything after the first dot. Example: Documentation can be found in the Bash manual. Look for ${parameter%word} and ${parameter%%word} trailing portion matching section.
Something like this should work (suggested by orip): if you prefer subshells, you could try the following (though it is more fragile): Git will invoke SSH which will find its agent by environment variable; this will, in turn, have the key loaded. Alternatively, setting HOME may also do the trick, provided you are willing to … Read more
If you are using the Git Bash shell, you can use the following trick: This is actually the same as: Then, you can use git add webpage.html to stage the file.
Tutorial A friend wrote a bash script to automatically restart a minecraft (spigot) server in the event of a crash or with the command “/stop” when using screen. There are several seconds to cancel the restart with Enter. In addition, the exit codes of the previous session are written to a file, which can be … Read more
Note: For a POSIX-compliant solution, see this answer. ${BASH_SOURCE[0]} (or, more simply, $BASH_SOURCE[1] ) contains the (potentially relative) path of the containing script in all invocation scenarios, notably also when the script is sourced, which is not true for $0. Furthermore, as Charles Duffy points out, $0 can be set to an arbitrary value by the caller.On the flip side, $BASH_SOURCE can be empty, if no named file is involved; e.g.:echo ‘echo “[$BASH_SOURCE]”‘ | … Read more