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

Bash aliases set through module aren't escaped #16973

Closed
8573 opened this issue Jul 15, 2016 · 9 comments
Closed

Bash aliases set through module aren't escaped #16973

8573 opened this issue Jul 15, 2016 · 9 comments

Comments

@8573
Copy link
Contributor

8573 commented Jul 15, 2016

Issue description

Bash aliases defined with the programs.bash.shellAliases configuration option are defined (1) in /etc/bashrc as —

alias ${k}='${v}'

— where ${k} and ${v} (which are variables in Nix, not in Bash) correspond to, respectively, the keys and values of the attribute set that is the value of programs.bash.shellAliases.

No escaping is performed on these values, so if one uses the apostrophe character in an alias defined in programs.bash.shellAliases, such as —

programs.bash.shellAliases = {
  "foo" = "foo --bar='baz qux'";
}

— then the bash module will emit the following problematic line in /etc/bashrc

alias foo='foo --bar='baz qux''

— which is equivalent to —

alias foo='foo --bar=baz' qux

— which first defines an alias foo, then queries the alias qux. No such alias exists, so "bash: alias: qux: not found" is printed each time one starts an interactive Bash instance.

Steps to reproduce

Use programs.bash.shellAliases to define an alias containing an apostrophe, as above.

Technical details

  • System: NixOS 16.09pre85931.125ffff (Flounder)
  • Nix version: nix-env (Nix) 1.11.2
  • Nixpkgs version: "16.09pre85931.125ffff"
@Profpatsch
Copy link
Member

(triage) is this still reproducible? If yes, would you be willing to prepare a pull request? I can support you if you have questions.

@8573
Copy link
Contributor Author

8573 commented Jun 24, 2018

I confirm that I still can reproduce this issue, but (my apologies) I haven't time to try to fix it.

@nagisa: As you also encountered this issue, would you be willing to try to patch it?

@8573
Copy link
Contributor Author

8573 commented Jun 24, 2018

I forgot to add the nix-info -m output for the system on which I reproduced the issue, which is as follows:

  • system: "x86_64-linux"
  • host os: Linux 4.14.48, NixOS, 18.09pre143771.a8c71037e04 (Jellyfish)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.0.4
  • channels(root): "nixos"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

@8573
Copy link
Contributor Author

8573 commented Oct 4, 2018

I think #47471 has fixed the same issue for zsh.

8573 added a commit to 8573/nixpkgs that referenced this issue Oct 6, 2018
This patch uses the library function `lib.escapeShellArg` to improve
the handling of shell aliases in the NixOS module `bash`, copying the
corresponding change made to the `zsh` module in commit
1e211a7 (for which GitHub pull
request NixOS#47471 was filed).

This patch resolves GitHub issue NixOS#16973.

This change presumably also should be copied to the `fish` module, but
I don't know `fish` syntax so that won't be done by me.

GitHub: Close NixOS#16973.
@timokau timokau closed this as completed Oct 6, 2018
@timokau
Copy link
Member

timokau commented Oct 6, 2018

Fixed by @8573 in #47984.

@8573
Copy link
Contributor Author

8573 commented Oct 7, 2018

Huh, I wonder why this ticket didn't close automatically when d8bcd2c was merged.

@timokau
Copy link
Member

timokau commented Oct 7, 2018

Because you have to use certain keywords github understands in either the PR description or the commit message, for example "Fixes #16973" would work.

@8573
Copy link
Contributor Author

8573 commented Oct 7, 2018

Because you have to use certain keywords github understands in either the PR description or the commit message, for example "Fixes #16973" would work.

I did, and GitHub puts a tooltip on the keyword in its rendering of the commit message that would seem to imply that it understood me.

@timokau
Copy link
Member

timokau commented Oct 8, 2018

True, that is weird.

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

No branches or pull requests

3 participants