Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to detect Operating system and assign it to variable? #396

Closed
shinebayar-g opened this issue Nov 4, 2020 · 1 comment
Closed

How to detect Operating system and assign it to variable? #396

shinebayar-g opened this issue Nov 4, 2020 · 1 comment
Labels
type: bug Something not working as intended.

Comments

@shinebayar-g
Copy link

shinebayar-g commented Nov 4, 2020

  • Task version: 3.0
  • OS: Ubuntu 18.04

I'm trying to detect operating system of the server and assign it to variable. Here is my Taskfile.

version: '3'

vars:
  DETECTED_OS:
    sh: |
        if [[ "$OSTYPE" == "linux-gnu"* ]]; then
          echo "linux-gnu"
        elif [[ "$OSTYPE" == "darwin"* ]]; then
          echo "darwin"
        elif [[ "$OSTYPE" == "cygwin" ]]; then
          echo "cygwin"
        elif [[ "$OSTYPE" == "msys" ]]; then
          echo "msys"
        elif [[ "$OSTYPE" == "win32" ]]; then
          echo "win32"
        elif [[ "$OSTYPE" == "freebsd"* ]]; then
          echo "freebsd"
        else
          echo "unknown"
        fi

tasks:
  os:
    desc: Detect operating system
    cmds:
      - echo "{{.DETECTED_OS}}"
    silent: true

Edit: Initial issue was solved, I was missing " symbol around variable. Above script is supposed to return linux-gnu since I'm running it on Ubuntu 18.04 server (It returns linux-gnu if I run it as bash script). But it's returning unknown when run as task. Does anyone know how to make it work?

This suggests, task scripts cannot access host OS ENVs?

@shinebayar-g shinebayar-g changed the title Cannot make multiline dynamic variable working How to detect Operating system and assign it to variable? Nov 4, 2020
@andreynering andreynering added the type: bug Something not working as intended. label Dec 5, 2020
@andreynering
Copy link
Member

Hi @shinebayar-g,

That sounds like an issue with the Shell interpreter library that Task uses: https://github.com/mvdan/sh

Can you please report this issue there? Feel free to ping me and mention this original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something not working as intended.
Projects
None yet
Development

No branches or pull requests

2 participants