Skip to content

Change $0 when executing tools #3130

@suzuki-shunsuke

Description

@suzuki-shunsuke

Feature Overview

Enable us to change $0 when executing tools like exec's -a option.

exec -a assumego granted "$@" # Execute granted as assumego

Why is the feature needed?

Some tools change their behavior by $0.

For example, granted changes the behavior based on args[0].

https://github.com/common-fate/granted/blob/e8de3ec7d62d543062d8be802b27abb3d8fac429/cmd/granted/main.go#L37-L44

	// Use a single binary to keep keychain ACLs simple, swapping behavior via argv[0]
	var app *cli.App
	switch filepath.Base(os.Args[0]) {
	case "assumego", "assumego.exe", "dassumego", "dassumego.exe":
		app = assume.GetCliApp()
	default:
		app = granted.GetCliApp()
	}

Workaround

Create shell scripts like this.

aquaproj/aqua-registry#27177 (comment)

~/bin/assumego

#!/usr/bin/env bash

set -eu

granted=$(aqua which granted) # Get the absolute path of granted
exec -a assumego "$granted" "$@" # Execute granted changing args[0] to `assumego` by `exec -a assumego`

Example Code

registry.yaml

files:
  - name: assumego
    src: granted
    arg0: assumego

Note

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions