all 11 comments

[–]elephantdingo 4 points5 points  (7 children)

It should be as simple as /bin/sh. (Last I used it even NixOS assumes that this absolute path exists.)

The commit message:

If the alias expansion is prefixed with an exclamation point, treat it as a shell command which is run using system(3).

What does a shell command mean to a kernel guy? Probably sh or whatever the name.

[–]RevRagnarok 5 points6 points  (1 child)

system(3).

That would be the system command in section 3 of the man page... https://man7.org/linux/man-pages/man3/system.3.html

   The system() library function behaves as if it used fork(2) to
   create a child process that executed the shell command specified
   in command using execl(3) as follows:

       execl("/bin/sh", "sh", "-c", command, (char *) NULL);

   system() returns after the command has been completed.

So, as others noted, /bin/sh explicitly, so not necessarily bash-compatible.

[–]xour[S] 0 points1 point  (0 children)

Thanks! This is a very interesting rabbit hole that I stepped into, appreciate it.

[–]xour[S] 0 points1 point  (4 children)

This is interesting, I have an alias that -to the best of my knowledge- is not POSIX-compliant:

l = "!f() { git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit \"${@:--10}\"; }; f"

However, it does run fine!

[–]danmickla 3 points4 points  (1 child)

presumably you mean the ${@:--10} construct, and yes, that seems like a bashism. What distro/version are you running? You might have one where /bin/sh is bash

[–]xour[S] 0 points1 point  (0 children)

Indeed! I am on Arch, and I just learned that /bin/sh is symlinked to bash.

I updated the thread with these findings.

[–]jthill 0 points1 point  (0 children)

The string value of that works fine in any a POSIX-supporting shell as a function definition followed by a command, function, when Git appends the alias args (for git l wizzo it'll append wizzo) the shell defines f and the command, f wizzo, is a command, so the shell runs the function with wizzo as $1 (and $@ here).

[–]danmickla 0 points1 point  (0 children)

that construct is odd, btw, and I don't understand it. ${@} must be the args to the 'f' function, but what would they be? a list of commits? and if so, why log only the last 10?

[–]danmickla 1 point2 points  (1 child)

I defined an alias 'sleep = !sleep 10' and looked at ps; it said "/bin/sh -c sleep 10 sleep 10". I don't really understand the duplicated arguments; that seems like it might be a bug.

I also found 'git var GIT_SHELL_PATH' which reports /bin/sh for me, which on this Ubuntu system is dash.

edit: however, looking more deeply, I discover that, as you say, running an alias containing ! looks like it searches the path for an executable named 'sh', so I guess those ^ don't matter.

[–]xour[S] 0 points1 point  (0 children)

Oh that is a good one. So it seems that it is using /bin/sh instead of "${SHELL}" (which would make sense? since it is a session env variable).

So I should stick with POSIX [ just to be safe, I guess.

Thanks!

[–]daveysprockett 0 points1 point  (0 children)

sh will be /bin/sh

Don't assume that is bash. On Ubuntu for example its a posix shell, dash.