Bash patterns I use weekly
will-keleher.com
Bash patterns I use weekly
1–10 of 115 posts
Re: Bash patterns I use weekly
#2git bisect is great and worth trying; it does what you're doing in your bash loop, plus faster and with more capabilities such as logging, visualizing, skipping, etc.
The syntax is: $ git bisect run [arguments]
Re: Bash patterns I use weekly
#3> git bisect is the "real" way to do this, but it's not something I've ever needed git bisect is great and worth trying; it does what you're doing in your bash loop, plus faster and with more capabilities such as logging, visualizing, skipping, etc. The syntax is: $ git bisect run [arguments] https://git-scm.com/docs/git-bisect
Re: Bash patterns I use weekly
#4 for route in foo bar baz do
curl localhost:8080/$route
done
That's just begging go wonky. Should be stuff="foo bar baz"
for route in $stuff; do
echo curl localhost:8080/$route
done
Some might say that it's not absolutely necessary to abstract the array into a variable and that's true, but it sure does make edits a lot easier. And, the original is missing a semicolon after the 'do'.I think it's one reason I dislike lists like this- a newb might look at these and stuff them into their toolkit without really knowing why they don't work. It slows down learning. Plus, faulty tooling can be unnecessarily destructive.
Re: Bash patterns I use weekly
#5 some_command &
some_other_command &
waitRe: Bash patterns I use weekly
#6I want to like this, but the for loop is unnecessarily messy, and not correct. for route in foo bar baz do curl localhost:8080/$route done That's just begging go wonky. Should be stuff="foo bar baz" for route in $stuff; do echo curl localhost:8080/$route done Some might say that it's not absolutely necessary to abstract the array into a variable and that's true, but it sure does make edits a lot easier. And, the orig…
Re: Bash patterns I use weekly
#7I want to like this, but the for loop is unnecessarily messy, and not correct. for route in foo bar baz do curl localhost:8080/$route done That's just begging go wonky. Should be stuff="foo bar baz" for route in $stuff; do echo curl localhost:8080/$route done Some might say that it's not absolutely necessary to abstract the array into a variable and that's true, but it sure does make edits a lot easier. And, the orig…
stuff=("foo foo" "bar" "baz")
for route in "${stuff[@]}"; do
curl localhost:8080/"$route"
doneRe: Bash patterns I use weekly
#8You can use `wait` to wait for jobs to finish. some_command & some_other_command & wait
In bash you can fix that by looping around, checking for status 127, and using `-n` (which waits for the first job of the set to complete), but not all shells have `-n`.
Re: Bash patterns I use weekly
#9 > SECONDS
bash: SECONDS: command not found
> SECONDS=0; sleep 5; echo $SECONDS;
5
> echo "Your command completed after $SECONDS seconds";
Your command completed after 41 seconds
> echo "Your command completed after $SECONDS seconds";
Your command completed after 51 seconds
> echo "Your command completed after $SECONDS seconds";
Your command completed after 53 seconds