^word^replacement^ on all matches in Bash?
Try this: $ echo oneone oneone $ !!:gs/one/two/ # Repeats last command; substitutes ‘one’ –> ‘two’. twotwo
Try this: $ echo oneone oneone $ !!:gs/one/two/ # Repeats last command; substitutes ‘one’ –> ‘two’. twotwo
The syntax <(…) is only supported by BASH. For any POSIX shell, use this approach: sh -c ‘tail -n 1000 -F catalina.out | if grep -qP –line-buffered “.+” ; then …’ i.e. move the stdin redirection in front of the if with a pipe. The if will pass stdin on to the grep. if tail … Read more
The third form is not at all like the other two — but to understand why, we need to go into the order of operations when bash in interpreting a command, and look at which of those are followed when each method is in use. Bash Parsing Stages Quote Processing Splitting Into Commands Special Operator … Read more
Accrding to: http://www.vias.org/linux-knowhow/bbg_sect_08_02_01.html : -r If this option is given, backslash does not act as an escape character. The backslash is considered to be part of the line. In particular, a backslash-newline pair may not be used as a line continuation. It works on my machine. $ echo ‘\&|’ | while read -r in; do … Read more
You should use shuf command =) cat file1 file2 | shuf Or with Perl : cat file1 file2 | perl -MList::Util=shuffle -wne ‘print shuffle <>;’
Here are my 2 cents on this and it represents my personal opinion as well as understanding on the topic. Using aliases with functions is to some extent a personal preference of developers. I will add some differences between the two approaches, which may also account for personal preferences of using aliases vs functions There … Read more
The simple solution: output=$(complex_command) status=$? if (( status == 0 )); then : stuff with “$output” fi : more code if (( status == 0 )); then : stuff with “$output” fi Or more eleganter-ish do_complex_command () { # side effects: global variables # store the output in $g_output and the status in $g_status g_output=$( … Read more
It’s called a shebang, and tells the parent shell which interpreter should be used to execute the script. #!/bin/sh <——— bourne shell compatible script #!/usr/bin/perl <– perl script #!/usr/bin/php <— php script #!/bin/false <—— do-nothing script, because false returns immediately anyways. Most scripting languages tend to interpret a line starting with # as comment and … Read more
Great question. I use a pattern like this for most of my scripts: #!/bin/bash main() { foo bar baz } foo() { } bar() { } baz() { } main “$@” You can read the code from top to bottom, but it doesn’t actually start executing until the last line. By passing “$@” to main() … Read more
Use: find . -name “*.t1” -exec bash -c ‘mv “$1” “${1%.t1}”.t2’ – ‘{}’ + If you have rename available then use one of these: find . -name ‘*.t1’ -exec rename .t1 .t2 {} + find . -name “*.t1” -exec rename ‘s/\.t1$/.t2/’ ‘{}’ +