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

$GID not found #561

Closed
antonio-antuan opened this issue Aug 27, 2021 · 15 comments · Fixed by #580
Closed

$GID not found #561

antonio-antuan opened this issue Aug 27, 2021 · 15 comments · Fixed by #580

Comments

@antonio-antuan
Copy link

Example Taskfile showing the issue

version: '3'

silent: false

tasks:
  check:
    desc: Generates proto with prepared docker-image
    cmds:
      - echo $GID
      - echo $UID

check it:

✗ task check
task: [check] echo $GID

task: [check] echo $UID
1000
✗ echo $GID
1000
✗ echo $UID
1000

@antonio-antuan antonio-antuan added the type: bug Something not working as intended. label Aug 27, 2021
@sylv-io
Copy link
Contributor

sylv-io commented Sep 6, 2021

I was not able to reproduce:

[sylv dev]$ echo $GID
100
[sylv dev]$ echo $UID
1337
[sylv dev]$ ./task check
task: [check] echo $GID
100
task: [check] echo $UID
1337
  • OS: Linux on 5.13.13-arch1-1

what shell are you using?

subsequent edit: in this case the GID env var was set explicily. That why it has worked.

@antonio-antuan
Copy link
Author

Same results with bash. Full output:

~ /bin/bash
$ task check
task: [check] echo $GID

task: [check] echo $UID
1000
$ cat Taskfile.yml 
version: '3'

silent: false

tasks:
  check:
    desc: Generates proto with prepared docker-image
    cmds:
      - echo $GID
      - echo $UID
$ bash --version
GNU bash, version 5.1.8(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ 
exit
~ zsh --version
zsh 5.8 (x86_64-pc-linux-gnu)
~ task check   
task: [check] echo $GID

task: [check] echo $UID
1000
~ task --version
Task version: v3.7.0 (h1:8dDFv12/Lxi6PHkYNIIm7N6v6oRGxePpLK67LuMh/Rs=)

@sylv-io
Copy link
Contributor

sylv-io commented Sep 6, 2021

I see. You are using zsh:

arch% echo $GID
1337
arch% echo $UID
1337
arch% ~/go/bin/task check
task: [check] echo $GID
task: [check] echo $UID
1337

IIUIC: zsh does set GID internaly.
However analog to bash, mvdan.cc/sh does only set the UID variable, but not GID. (See: code)
There is already an issue in regards to this problem: mvdan/sh#514
However, it looks like the maintainer did not understand the authors problem and it was closed accordingly.

Therefore it is an Issue related to mvdan.cc/sh.
Maybe you could address the issue there.

@sylv-io
Copy link
Contributor

sylv-io commented Sep 6, 2021

As a workaround, you could useUID=$(id -u) and GID=$(id -g)

@sylv-io
Copy link
Contributor

sylv-io commented Sep 6, 2021

after patching mvdan.cc/sh, i was able to access GID:

diff --git a/interp/api.go b/interp/api.go
index 6ac3dc34..b7526c56 100644
--- a/interp/api.go
+++ b/interp/api.go
@@ -444,6 +444,13 @@ func (r *Runner) Reset() {
                        Str:      strconv.Itoa(os.Getuid()),
                })
        }
+       if !r.writeEnv.Get("GID").IsSet() {
+               r.setVar("GID", nil, expand.Variable{
+                       Kind:     expand.String,
+                       ReadOnly: true,
+                       Str:      strconv.Itoa(os.Getgid()),
+               })
+       }
        r.setVarString("PWD", r.Dir)
        r.setVarString("IFS", " \t\n")
        r.setVarString("OPTIND", "1")

Output:

[sylv dev]$ task check
task: [check] echo $GID
100
task: [check] echo $UID
1337
[sylv dev]$ echo $GID

[sylv dev]$ echo $UID
1337

@antonio-antuan
Copy link
Author

What about cross-platform feature in Taskfile? :)
If it is exist looks like Taskfile should provide some API (or yeap, several global variables) like UID, GID.

If you think that the idea is bad (or does not fit Taskfile ideas) I think you can close this issue: the problem is not yours.

Anyway, thanks for your research.

@sylv-io
Copy link
Contributor

sylv-io commented Sep 6, 2021

What about cross-platform feature in Taskfile? :)
If it is exist looks like Taskfile should provide some API (or yeap, several global variables) like UID, GID.

Hmm I'm new here but my guess it relates only to mvdan/sh and would be overkill in task.

If you think that the idea is bad (or does not fit Taskfile ideas) I think you can close this issue: the problem is not yours.

Lets see what the maintainer of mvdan/sh think about it. I created an PR which would fix your issue. But maybe there is a valid reason not to add GID internally. (e.g. maybe not POSIX Shell compliant)

Anyway, thanks for your research.

np. :) was an opportunity to learn something new.

@antonio-antuan
Copy link
Author

antonio-antuan commented Sep 6, 2021 via email

@sylv-io
Copy link
Contributor

sylv-io commented Sep 6, 2021

I think it can fix only mvdan/sh, not zsh, bash, sh, fish and so on... пн, 6 сент. 2021 г., 18:49 Marcello Sylvester Bauer < @.***>:

What about cross-platform feature in Taskfile? :) If it is exist looks like Taskfile should provide some API (or yeap, several global variables) like UID, GID. Hmm I'm new here but my guess is, is relates only to mvdan/sh and would be overkill in task. If you think that the idea is bad (or does not fit Taskfile ideas) I think you can close this issue: the problem is not yours. Lets see what the maintainer of mvdan/sh think about it. I created an PR <mvdan/sh#723> which would fix you issue. But maybe there is a reason not to add GID internally. (e.g. maybe not POSIX Shell compliant) Anyway, thanks for your research. np. :) was an opportunity to learn something new. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#561 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRBAYD6TQI4WKZHLYZGNGLUATPIXANCNFSM5C5OAJMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

sure, the scope of this issue is task which only uses mvdan/sh.

@antonio-antuan
Copy link
Author

antonio-antuan commented Sep 7, 2021 via email

@sylv-io
Copy link
Contributor

sylv-io commented Sep 7, 2021

So and what about other shells? :( пн, 6 сент. 2021 г., 22:46 Marcello Sylvester Bauer < @.>:

I think it can fix only mvdan/sh, not zsh, bash, sh, fish and so on... пн, 6 сент. 2021 г., 18:49 Marcello Sylvester Bauer < @.
>: … <#m_-3325311544333467101_> What about cross-platform feature in Taskfile? :) If it is exist looks like Taskfile should provide some API (or yeap, several global variables) like UID, GID. Hmm I'm new here but my guess is, is relates only to mvdan/sh and would be overkill in task. If you think that the idea is bad (or does not fit Taskfile ideas) I think you can close this issue: the problem is not yours. Lets see what the maintainer of mvdan/sh think about it. I created an PR <mvdan/sh#723 <mvdan/sh#723>> which would fix you issue. But maybe there is a reason not to add GID internally. (e.g. maybe not POSIX Shell compliant) Anyway, thanks for your research. np. :) was an opportunity to learn something new. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#561 (comment) <#561 (comment)>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRBAYD6TQI4WKZHLYZGNGLUATPIXANCNFSM5C5OAJMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub . sure, the scope of this issue is task which only uses mvdan/sh. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#561 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRBAYEEKGPYIYKFV4HCMCDUAULCBANCNFSM5C5OAJMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

hmm i guess there is a miss understanding. If you want to add GID internally into other shells, you can give it a try (e.g. in bash).
But i don't see the point to do it. Looks like the maintainer appreciated this change in mvdan/sh. So this issue in task should be fixt. Everything else is out of scope.

@antonio-antuan
Copy link
Author

ok, the issue is not from Taskfile scope and it's a problem of specific shell, ok. but I do not understand why are we speaking about mbdan/sh here :D

@sylv-io
Copy link
Contributor

sylv-io commented Sep 7, 2021

ok, the issue is not from Taskfile scope and it's a problem of specific shell, ok. but I do not understand why are we speaking about mbdan/sh here :D

Because the issue topic is $GID not found and task only uses mbdan/sh.

@antonio-antuan
Copy link
Author

antonio-antuan commented Sep 8, 2021 via email

@sylv-io
Copy link
Contributor

sylv-io commented Sep 8, 2021

mvdan/sh#723 got merged, but we should wait for the next module release (v3.3.2), since this is not really an urgent change.

@pd93 pd93 removed the type: bug Something not working as intended. label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants