I have a script that displays every file in a directory that has a filename containing 5 or less characters:
#!/bin/bash
ls | egrep '^.{0,5}$'
Example directory:
foobar
foo
bar
Output:
foo
bar
But when I try to use a variable in place of 5 like seen below, I get no output. No error, so I'm assuming it's still looking for some kind of range. But just not 0-5.
#!/bin/bash
declare -i num=5
ls | egrep '^.{0,$num}$'
How do I use a variable inside on the curly braces?