Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8943103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:41:30+00:00 2026-06-15T11:41:30+00:00

@echo off set test=%1 if %1== ( set test=default echo %test% ) else (

  • 0
@echo off
set test=%1

if "%1"=="" (
set test=default
echo %test%
) else (
set test=%1
echo %test%
)

Test:

test.bat

Output:

ECHO is off

Problem: The ‘default’ string cannot be assigned as a value to variable ‘test’. I’ve found out that test string’s value is still %1 which has no value

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:41:32+00:00Added an answer on June 15, 2026 at 11:41 am

    It’s the standard batch beginner bug.
    Percent expansion doesn’t work in parenthesis as you expected.
    It expands when the complete block is parsed, before any of the lines are executed.

    So %test% is expanded to nothing, the value before it enters the block.

    The solution is to use delayed expansion here, as !test! will be expanded at execution not parse time.

    @echo off
    setlocal EnableDelayedExpansion
    set test=%1
    
    if "%1"=="" (
      set test=default
      echo !test!
    ) else (
      set test=%1
      echo !test!
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you run test.bat blabla,blabla,^>blabla, blaby test.bat implementation: @SETLOCAL @ECHO OFF SET list=%~1 ECHO
I have created below bat file to run my RMI server @echo Off set
I have bat file like below with name myBat.bat 1) @echo off set CLASSPATH=%CLASSPATH%;C:\Documents
I have a batch script that looks like this: Test.bat @echo off :: Starts
I have a problem here. First things first, the code: Contents of test.bat: @echo
echo off set /a a=0 :start if %a% LEQ 21( echo test set /a
I don't know what the problem is with this batch file: @ECHO OFF SET
@echo off rem ffmpeg -i test.ts 2>&1 | find Duration > duration.txt rem set
I have the following code in my batch file @ECHO OFF SET /P NAME=Enter
Here's my batch script: @echo off cls set SOURCE=svn://vcrep/UXP/ercpac/trunk/ set SVN=C:\Program Files\TortoiseSVN\bin %SVN%\TortoiseProc.exe /command:update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.