Question

I am trying to filter out some strings using case statement.

case $HOST in     
          Linux|Windows|Storage*)

I want to filter out the hosts which have names like this

  1. test_prd_linux
  2. test_prd_windows

How can i include *prd* in the above case statment? Something like this?

case $HOST in  
       Linux|Windows|Storage|*prd*)
Was it helpful?

Solution

These are globs, not regular expressions.

Yes, the glob *prd* will match the cases you have as examples (though I would use the more specific pattern *_prd_* if these examples are representative).

However, you also changed Storage* to Storage, so this will no longer match some strings it used to match. Perhaps put the glob star back.

case $HOST in
    Linux|Windows|Storage*|*_prd_*) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top