1

How can I skip an argument like %~1 in the %*?

@echo off
title  
cls
:loop
set /p command=
call :command %command%
goto :loop
:command
if "%~1"=="title"(
  %~1 %*
)
goto :eof

I'm trying to create my own cmd in there.

But I have a problem: when I try to set my cmd's window title the output is:

title test title

Or when I create an echo command, the output is:

echo test echo command

That is, the command itself is also inside the output.

Can we skip %~1 in the %*?

Or should I use any other command?

6
  • 2
    %* represents all args no exceptions, you could use shift to remove an arg from the numbered list and though gain access to former agrs 10 and up.
    – LotPings
    Sep 7, 2019 at 17:46
  • @LotPings example please :) Sep 7, 2019 at 17:51
  • 2
    read the help shift /? or online
    – LotPings
    Sep 7, 2019 at 17:54
  • @LotPings nope, it isn't skipping "%~1" argument while i'm using "%*". Sep 7, 2019 at 18:10
  • 1
    Read the help and my 1st comment again.
    – LotPings
    Sep 7, 2019 at 18:13

2 Answers 2

1

If splitting a delimited string into tokens is the objective, including, as here, separating the first delimited token from the remainder of the string, then FOR /F is much more flexible and useful.

@echo off
title  
cls
:loop
set /p command=
for /f "tokens=1* delims= " %%A in ("%command%") do if /I "%%~A"=="title" %%A %%B
goto :loop
2
0

You can use the direct batch line interpretion as follows:

@echo off
title  
cls
:loop
set /p command=
call :command_%command%
goto :loop


:command_title
title %*
exit /b

E. g. if user types "title this is the name of the window" batch executes following: call :command_title this is the name of the window. Inside of :command_title the %* just holds the extra arguments, so %1 doesn't exist in that sense.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .