0

I have a script that is using a switch case to check for file extensions and do something on that.

# Gets the extension of the file
Extension=${file##*.}
        case ${Extension} in
        abc)
            #Do something
        pqr)
            #Do something
        *)
            #Print the usage

The script is called as "script.sh -G filename.abc".

My requirement is to call this script with a file name having no extension. For ex: script.sh -G FileName.

How do i implement this in my current script?

6055
  • 439
  • 1
  • 4
  • 14

1 Answers1

1

Always put your variables in quotes unless you want it subjected to word splitting and globbing.

case "$Extension" in
...
esac

When you leave out the quotes, and the extension is empty, your statement expands to:

case in

which is incorrect syntax.

Barmar
  • 741,623
  • 53
  • 500
  • 612