The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



Thread: Case Statement
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #13 (permalink)  
Old 04-01-2004
Perderabo's Avatar
Perderabo Perderabo is offline
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,334
I don't think that we're shouting. But you are continually tripping over the shortcomings of sh and then inquiring about it. We don't meant to get on your nerves.

Whether or not something like:
if [ $file = *.[a-z] ]
will even work at all depends on the contents of the current directory. I had to copy the script to an otherwise empty directory to ensure that the shell would not match "*.[a-z]". Once I did that that, the test command will see the string *.[a-z]. But the test command does not do pattern matching. So to trigger the "if" statement, copy your script to an otherwise empty directory and then use:
dosRename Mike '*.[a-z]'

You see that is the only string that will match the *.[a-z] in the if statement.

I guess that I'm not supposed to mention that this would be a snap with ksh, so I won't.

With sh, the only way to match a string against a pattern is with the case statement. Or you can do stuff like using sed to delete the pattern and see if anything is left in the string. The case statement idea is the better solution since it is a builtin command.
Reply With Quote