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

Support commandline local variables #1377

Closed
creack opened this issue Mar 29, 2014 · 6 comments
Closed

Support commandline local variables #1377

creack opened this issue Mar 29, 2014 · 6 comments

Comments

@creack
Copy link

creack commented Mar 29, 2014

It would be nice to have the ability to set a temporary environment variable.

Right now, in order to do this, I have to write;
set -x VAR value; cmd; set -e VAR.

In any other shell, you can do this:
VAR=value cmd

Fish is not any other shell, I know.. But I don't think it is a reason to strip must have features like this ;)

@zanchey
Copy link
Member

zanchey commented Mar 29, 2014

See also #438, #587, #809, #823...

@creack
Copy link
Author

creack commented Mar 29, 2014

@zanchey What is the official position on this? If I sum-up the threads:

$> fish -v
fish, version 2.1.0

$> env VAR=world echo hello $VAR
hello

$> env VAR=world; echo hello $VAR
#...
#displays my whole env
hello

$> begin; set -lx VAR world; echo hello $VAR; end
hello world

$> function myfct; echo hello $VAR; end
$> begin; set -lx VAR world; myfct; end
hello

$> set -lx VAR world; echo hello $VAR
hello world
#leaks the var (expected I think)

@ridiculousfish
Copy link
Member

env is an external command, so it can't do things like modify the value of a variable before it gets expanded. This is one of many reasons why it's an imperfect substitute for the foo=bar syntax in POSIX shells.

This is obviously a very popular request, but the foo=bar syntax is not in line with fish's "everything is a command" design principle. So how can we satisfy these use cases in a way that's consistent with what makes fish fish? That's the question to think about.

If you agree this is the same as #438, I'd like to close as a dup of that.

@creack
Copy link
Author

creack commented Mar 29, 2014

I agree, but 1) the solution proposed does not work (and the faq neither) 2) I am sure we can find an easy way to work around this. What about an extra flag to set? Like set -l but scoped to the commandline instead of the function

@maxfl
Copy link
Contributor

maxfl commented Mar 29, 2014

Here is the right way:

set var hello
function fcn -S
    echo $var
end
begin
    set -l var world
    echo $var
    fcn
end

By default function doesn't see outer scope local variables.

@ridiculousfish
Copy link
Member

Let's track in #438

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants