Batch File Syntax Help

I've made a script to help me get past some restrictions at my school and I've been experimenting with the syntax for the 'if' test.

Here's some code that is somewhat similar to what I want:
Code:
@echo off
:temp
cls
echo type 's' to echo string
set /p ch=
    if %ch%==(s S) (
        goto hello
    )
cls
echo Not a valid paremeter
pause
goto temp

:hello
cls
echo hello
pause
goto temp
Basically I want my script to accept both upper and lower cases. So if I type 's' or 'S', it will do whatever is nested under the if block. And if the input is anything other than 'S' or 's', it will loop back to the temp location.

I know that if I type it as:
Code:
set /p ch=
    if %ch%==s (
        goto hello
    )
cls
it works; as I've been doing with my script so far.

My question is, how would I be able write the if command so that it will do whatever is nested under it regardless of whether the case is upper or lower?

Thanks.

Edit: I just realized that I can use the 'else' statement to fall back on, instead of my 'manual' method.
 
Last edited:

My Computer

System One

  • Manufacturer/Model
    Acer Aspire 5630
    CPU
    Intel Core 2 Duo T5500 1.66GHz 65nm 667MHz FSB 2MB L2
    Motherboard
    Acer Grapevine Intel i945GM Chipset
    Memory
    2x1GB DDR2 333MHz
    Graphics Card(s)
    Intel Integrated GMA 950 256MB
    Sound Card
    Realtek High Definition Audio
    Monitor(s) Displays
    15.4" WXGA Acer CrystalBrite LCD 16ms
    Screen Resolution
    1280x800
    Hard Drives
    200GB 5400rpm Toshiba MK2035GSS ATA-7, 250GB 7200rpm Maxtor External USB Hard Drive
you just need the /I switch on your if statement which does case insensitive comparisons of the string e.g.

if /I %ch%==s goto hello

:)
 

My Computer

System One

  • CPU
    2x AMD FX-74 @ 3.0GHz
    Motherboard
    ASUS L1N64-SLI
    Memory
    4GB OCZ Reaper DDRII
    Graphics Card(s)
    2x BFG 8800GTX OC 768MB (SLI)
    Sound Card
    Creative X-Fi Fatl1ty
    Monitor(s) Displays
    HP L2045w
    Screen Resolution
    1680x1050
    Hard Drives
    2x 500GB Samsung T166 SATAII
    PSU
    Enermax Galaxy 1000W PSU
    Case
    Thermaltake Armor Extreme Case
    Keyboard
    Microsoft Multimedia Keyboard
    Mouse
    Razer DeathAdder
    Internet Speed
    8Mb ADSL (UK Online)
Thanks a lot for that, it helped solve my problem. I guess I didn't read the 'if /?' 'man' page, if you will, correctly.
 

My Computer

System One

  • Manufacturer/Model
    Acer Aspire 5630
    CPU
    Intel Core 2 Duo T5500 1.66GHz 65nm 667MHz FSB 2MB L2
    Motherboard
    Acer Grapevine Intel i945GM Chipset
    Memory
    2x1GB DDR2 333MHz
    Graphics Card(s)
    Intel Integrated GMA 950 256MB
    Sound Card
    Realtek High Definition Audio
    Monitor(s) Displays
    15.4" WXGA Acer CrystalBrite LCD 16ms
    Screen Resolution
    1280x800
    Hard Drives
    200GB 5400rpm Toshiba MK2035GSS ATA-7, 250GB 7200rpm Maxtor External USB Hard Drive
Back
Top