Skip to content

Mix cmd in alias no longer supports globs #14506

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

Closed
kenny-evitt opened this issue May 19, 2025 · 9 comments
Closed

Mix cmd in alias no longer supports globs #14506

kenny-evitt opened this issue May 19, 2025 · 9 comments

Comments

@kenny-evitt
Copy link
Contributor

Elixir and Erlang/OTP versions

Erlang/OTP 27 [erts-15.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.19.0-dev (ea2ae22) (compiled with Erlang/OTP 27)

Operating system

macOS 14.1.2 (23B92)

Current behavior

Example alias from mix.exs:

  defp aliases do
    [
      cp_test: [
        "cmd cp -R web/static/assets/* priv_test/static"
      ],
      ...
    ]
  end

Running the alias:

$ mix cp_test
cp: web/static/assets/*: No such file or directory
** (exit) 1
    (mix 1.19.0-dev) lib/mix/tasks/cmd.ex:82: Mix.Tasks.Cmd.run/1
    (mix 1.19.0-dev) lib/mix/task.ex:499: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.19.0-dev) lib/mix/task.ex:573: Mix.Task.run_alias/6
    (mix 1.19.0-dev) lib/mix/cli.ex:131: Mix.CLI.run_task/2
    /Users/kenny/.asdf/installs/elixir/main-otp-27/bin/mix:7: (file)

Expected behavior

In (some) previous Elixir versions, the same alias works as expected. It definitely works in 1.13.4.

The only workaround – to run cp with a glob (or at least *) – that I've found is to move the cp command to a shell script and modify the alias to run the script via a shell program, example:

  defp aliases do
    [
      cp_test: [
        "cmd bash cp_test.bash"
      ],
      ...
    ]
  end
@josevalim
Copy link
Member

This commit changed it: #14181

We can add a flag to enable shell like behavior once again.

@pxp9
Copy link

pxp9 commented May 20, 2025

Hello, I wanted to say that I compiled Elixir

Erlang/OTP 27 [erts-15.2.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit:ns]

Elixir 1.19.0-dev (ca069f7) (compiled with Erlang/OTP 27)

And did these steps and everything seems to work fine.

bin/mix new hello
cd hello

Add this in the mix.exs file.

      aliases: aliases()
  defp aliases do
    [
      copy: [
        "cmd cp -R lib/* src"
      ]
    ]
  end

Create the src folder

mkdir src

Run the alias with the expansion.

../bin/mix copy

Image

@josevalim
Copy link
Member

It may be a OS thing. cp in Linux may expand * while the one in macOS expects it to be expanded by the shell?

@pxp9
Copy link

pxp9 commented May 20, 2025

hey @josevalim, I dont think this is true, I have tried cp with single quotes (prevents shell expasion) and it does not find the file.

cp '*.yml' lib

it did not expanded to all yml files, it failed because it did not find *.yml file.

@kenny-evitt , could you tell us what cp version do you have ?

I think mine is the GNU cp 9.6 .

@josevalim
Copy link
Member

hey @josevalim, I dont think this is true, I have tried cp with single quotes (prevents shell expasion) and it does not find the file.

What about using it with the -R version?


@pxp9 I could reproduce it on macOS, although no way to get cps version:

STANDARDS
     The cp command is expected to be IEEE Std 1003.2 (“POSIX.2”) compatible.

HISTORY
     A cp command appeared in Version 1 AT&T UNIX.

macOS 15.3                                                                                    March 28, 2024                                                                                  

@pxp9
Copy link

pxp9 commented May 20, 2025

Hey @josevalim,

Image

now testing with different version of Nixos.

Image

without quoting works as before

cp (GNU coreutils) 9.6
Packaged by https://nixos.org
Copyright (C) 2025 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://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.

Written by Torbjörn Granlund, David MacKenzie, and Jim Meyering.

@josevalim
Copy link
Member

@pxp9 thank you, this is very unexpected because Elixir certainly isn't expanding -R anywhere?

In any case, I was adding a --shell flag, and I just realized this could be trivially fixed by invoking the shell directly:

cp_test: "cmd sh cp -R web/static/assets/* priv_test/static"

So that's my suggestion for @kenny-evitt going forward.

@kenny-evitt
Copy link
Contributor Author

@pxp9 I don't know how to tell what version of cp I have. The man page for cp just shows macOS 14.1 and April 17, 2022 (tho the latter might refer to when the man page itself was last updated?).

@josevalim Invoking the shell directly (in the alias command(s)) was exactly the workaround I found – I'm fine using that.

@kenny-evitt
Copy link
Contributor Author

@josevalim @pxp9 Thanks for your help! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants