[clug] Bash questions...

steve jenkin sjenkin at canb.auug.org.au
Sun May 1 21:59:27 MDT 2011


Good quote. quite apt :-)

One of the solutions that I wanted to try was using '=~' binary match in
'[[', the only way I can see to do a substring.

But I can't make it work with this shell :-(

like:
[once during initialisation]
sep=$(for i in {1..200};do echo -n '-';done)

To print a separator string.
[[ ${sep} =~ '-{20}' ]] && echo $BASH_REMATCH


Anyone done 'substrings' in bash?


Angus Gratton wrote on 2/05/11 12:40 PM:
> On Sun, 2011-05-01 at 11:39 +1000, steve jenkin wrote:
>> But without doing my usual, v. simple:
>>  echo "--------------------------------------------------" :-)
> 
> I realise this is something of a thought exercise, and that many
> solutions have the tongue firmly in the cheek, but as I read it I keep
> thinking of my favourite programming quote:
>         
>         "Programs must be written for people to read, and only
>         incidentally for machines to execute." 
>         — H. Abelson
> 
> and none of the alternatives really stacks up to the original in
> readability. It's simply very, very obvious what echo "------------"
> does. :)
> 
> 
> Although, there's always:
> 
> alias horizontal_separator='echo "--------------------------------------------------"'
> 
> horizontal_separator
> 
> 
> or
> 
> DASHES="--------------------------------------------------"
> 
> echo $DASHES
> 
> 
> or, for the brevity-conscious
> 
> alias sep---='echo "--------------------------------------------------"'
> 
> sep---
> 
> 
> ;)
> 
> - Angus
> 
> 


-- 


More information about the linux mailing list