1

I'm trying to remove incoming quotes for a doskey macro that will let me use "export" as "set". Here's what I have:

doskey export=set $*

Except when I run with the following:

export VAR="value"

I end up with:

VAR="value"

vs what I wanted:

VAR=value

I think I have to write a little method of sorts to 'clean' the input to set but I don't know how to do that - something like "for (var1=var2) do set var1=~var2", but I can't get anything like that to work.

Help!

Paul
  • 11
  • 1
  • There is not `export` command. In what way are you using `export`? If you want to set the value of an environment variable, use `SET "VAR=value" – lit Aug 05 '17 at 01:00
  • doskey.exe creates console aliases. By default it creates aliases that are in effect whenever "cmd.exe" does a cooked read from the console (i.e. calls `ReadConsole` or `ReadFile` on a console input handle). Aliases can also be created specifically for other executables such as python.exe. A console alias works by replacing text that's matched at the start of a line. It can't be used anywhere else in an input command that's read from the console. It also can't be used in a batch script. So it's really of limited value. – Eryk Sun Aug 05 '17 at 04:00
  • The console allows parameterizing the rest of the white-space delimited command line as `$1` up to `$9`, as well as `$*` for the entire command-line after the alias itself. You can use `$*` in the replacement string, e.g. in a `for` loop or whatever. But bear in mind that CMD will literally read the `for` loop from the console, so it has to be valid syntax for an interactive command line. It's not as if it's being evaluated like a function or calling an `export.bat` script. – Eryk Sun Aug 05 '17 at 04:07
  • You'll need to filter out those quotes before you execute the `export` statement (to avoid the complications accurately noted by eryksun). – Steven K. Mariner Aug 05 '17 at 15:49

1 Answers1

0

You can probably do it with a for loop too, but this is easier:

set ORIGARGS=%*
set ARGCOPY=
:copyargs
    set "ARGCOPY=%ARGCOPY% %~1"
    shift
    if not [%1]==[] goto:copyargs

ie. (line-by-line)

  1. save the original %* since we're going to destroy it.
  2. prepare a variable (ARGCOPY) to put the converted arguments into
  3. label (target of goto in line 6)
  4. append the first argument %1 to ARGCOPY, but remove quotes (%~1)
  5. shift all arguments to the left one space (i.e. what was %2 becomes %1, etc.)
  6. if we've reached the end of the arguments then %1 has no value, otherwise goto line 3, where the :copyargs label is located.

when you're done %ARGCOPY% will contain the parameters without quotes.

thebjorn
  • 26,297
  • 11
  • 96
  • 138
  • Wow, thanks and I appreciate the explanation of how that works. Now, how do I insert that into a doskey macro? – Paul Aug 07 '17 at 17:55
  • `export %ARGCOPY%` if `export` is your doskey macro. – thebjorn Aug 07 '17 at 19:02
  • Please remember to upvote all answers that were helpful, and select the answer that best answered your question. This will help future visitors, and to give me points :-) – thebjorn Aug 08 '17 at 19:10