New answers tagged

2 votes
Accepted

Bash Function Grep Mod

In bash and sh "$@" will expand all positional parameters so: cgrep () { clear clear grep "$@" } Note that $@ has to be double quoted to prevent word splitting, globbing, ...
  • 33.8k
0 votes

How can I/Should I default flags when running a command?

Aliases that use the same name are almost the entire point of aliases. An alias definition provides a string value that shall replace a command name when it is encountered alias grep='grep --ignore-...
  • 484
3 votes
Accepted

How can I/Should I default flags when running a command?

I am really surprised by that other post you mentioned, as it can be very misleading. Just because an alias doesn't use parameters doesn't mean that aliases cannot set parameters. Of course you can ...
  • 464
4 votes

How can I make time measurement DRY in my bash scripts?

What is wrong with time ./script.sh ? Simple example:- time sleep 5 real 0m5.001s user 0m0.001s sys 0m0.000s
  • 1,185
4 votes

How can I make time measurement DRY in my bash scripts?

In latest versions of bash (5.0+), there is a variable that give the time with precision of microseconds (6 fractional digits). If that is enough precision for your uses, you may try this script: #!/...
2 votes

How can I make time measurement DRY in my bash scripts?

Here is a version that requires associative arrays (bash, etc.) To be placed in an example timers.sh #!/bin/bash ######################################################################## declare -A ...
  • 93.9k
2 votes

How can I make time measurement DRY in my bash scripts?

In its simplest form, this sounds like what you're after. now(){ date -u +%s.%N } measure_time(){ local elapsed="$(bc <<<"$end_time-$start_time")" echo "Total ...
  • 3,868
0 votes

zsh: alias or shell function to only echo its command line, including shell control characters

This is a variation on the suggestion by Stéphane Chazelas, and it works for me. I corrected the original "Answer" here based on the comments, below, by Stéphane Chazelas ... set -o ...
  • 405
0 votes

zsh: alias or shell function to only echo its command line, including shell control characters

A trick to do this is to write an alias that ends with # to make the rest of the line a comment, then pull the line from the history. Comments must be enabled with setopt interactive_comments. However,...
0 votes
Accepted

Using bash return depending on return status of last command executed within a function

This should work tesverbos () { vb="${verbos+vbset}" test -n "$vb" }
1 vote

Using bash return depending on return status of last command executed within a function

How can I use only return at the end, taking the value of N, depending on the return status of [ -n vb ]? [ -n "$vb" ] return Or, if the test is the last command in the function, omit the ...
  • 93.9k

Top 50 recent answers are included