1. Summary

I don't find, how I can use command output as variable, use cross-platform syntax.

2. Example

For example, I want get URL of my remote git repository:

SashaChernykh@DESKTOP-EEOT0TN /cygdrive/d/SashaBranchReleaseIt
$ git ls-remote --get-url

I run command in Linux/Cygwin:

SashaChernykh@DESKTOP-EEOT0TN /cygdrive/d/SashaBranchReleaseIt
$ echo "URL is `git ls-remote --get-url`"
URL is https://github.com/Kristinita/SashaBranchReleaseIt.git

I run the same command in Windows cmd.exe.

D:\SashaBranchReleaseIt>echo "URL is `git ls-remote --get-url`"
URL is `git ls-remote --get-url`


D:\SashaBranchReleaseIt>echo "URL is $(git ls-remote --get-url)"
URL is $(git ls-remote --get-url)

doesn't work.

I don't find syntax, that will be compatible with Windows and UNIX both.

3. Conditions

3.1. Not expected

I'm looking for a solution, that would be possible run command in default Windows cmd.exe. Windows user is not obliged to establish Cygwin, Bash for Windows or another terminal.

3.2. Expected

Windows user can add in Path environment variable path to Cygwin, GnuWin32 CoreUtils commands or path for any UNIX tools, that ported to Windows.

4. Not helped

  1. I don't find, how I can solve my problem in answers for this question.

5. Do not offer

  1. Yes, I know, that in Windows I can get similar behavior (example), but them Windows-specific. I'm looking for cross-platform command, not Windows-specific.
  • Seems abitious; good luck! Perhaps this attempt will ... help? – Jeff Schaller Jan 30 '18 at 17:56
  • Related only: unix.stackexchange.com/q/71121/117549 – Jeff Schaller Jan 30 '18 at 17:57
  • Syntax of Unix shell scripts and Windows batch files is completely different, except for a couple of things that Windows copied (e.g. I/O redirection and piping). I don't think what you want is possible. – Barmar Jan 30 '18 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.