Search code examples
windowscmdcommand-lineterminal

How to send a command with arguments without spaces in Windows


Is there a way to execute a command with arguments in Windows without spaces?

echo 1 > a

Needs to be:

echo1>a

In Linux you can use ${IFS} but I didn't find it to work in Windows:

echo${IFS}1${IFS}>a

Solution

  • (echo(1)>a
    

    or

    (echo/1)>a
    

    can be done.

    An alternative is

    >a=echo/1
    

    because the =-sign is a token separator just like the SPACE (you may also use , or ; instead).

    But regard, that

    echo/1>a
    

    cannot be used, because 1> is then taken as the redirection operator.


    A completely different solution is to first assign a SPACE to a variable and then to use it:

    rem // This assigns a single space character:
    set "SPC= "
    rem // A space before `>` would also be echoed out, hence use parenthesis:
    (echo%SPC%1)>%SPC%a
    rem // Alternatively, rearrange the command line:
    >%SPC%a%SPC%echo%SPC%1
    

    This works, because immediate variable (%-)expansion happens before command token recognition.