Skip to main content

All Questions

-1 votes
1 answer
82 views

awk inside function causing errors

I'm trying to add the following to my .bashrc: cpu_info() { top -b -n1 | grep Cpu(s) | awk '{print $2 + $4}' } but bash is telling me: bash: .bashrc: line 131: syntax error near unexpected token `...
Mathew's user avatar
  • 243
-1 votes
2 answers
553 views

Test for a number in bash [duplicate]

Is this the correct way to test for a number, with double [[]] enclosing :digit: and single quotes surrounding the regex ? if [[ "$var" =~ '^[[:digit:]]+$' ]]; then
Vera's user avatar
  • 1
9 votes
1 answer
600 views

/RE/ vs. "RE" in awk

In awk, the first argument to the sub() and gsub() functions, the second argument to the match() function, and the optional third argument to split(), is an extended regular expression. Such an ...
Kusalananda's user avatar
  • 351k
8 votes
2 answers
3k views

How to write regexp literal in match expression?

This question is about the proper way to write regular expression literals in a match expression under bash. In zsh, the match below succeeds, as I expected: % [[ ' 123 ' =~ '^ [0-9]+ $' ]]; echo $? ...
kjo's user avatar
  • 16.2k
0 votes
2 answers
1k views

Why not seeing shell globs as a "dialect" of regex? [duplicate]

I often confuse Bash 3.x shell globs: ? # Match any single character. * # Match any string of characters (up until the asterisk). [set] # Match any character in set (but not the entire set ...
Arcticooling's user avatar
1 vote
2 answers
2k views

Using an shell glob (wildcard (*)) after a double quoted variable expansion

I read that it is a best practice to double quote all of your variable expansions in Bash. I also read that one cannot use a shell glob (wildcard(*)) right after a double quoted variable expansion. ...
Arcticooling's user avatar