Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git alias now fails saying "read: illegal option -t"

Tags:

git

alias

I just imported my git config onto my new laptop running Ubuntu20.04, but for some reason few of my git aliases using Bash read built-in now fail.

[alias]
    try = "!read -t 5 -n 1 -p 'Confirm? [Y|n] '"
$ echo "$SHELL, $(git --version)"
/bin/bash, git version 2.25.1

$ GIT_TRACE=1 git try
23:57:46.840752 git.c:703               trace: exec: git-try
23:57:46.840829 run-command.c:663       trace: run_command: git-try
23:57:46.841147 run-command.c:663       trace: run_command: 'read -t 5 -n 1 -p '\''Confirm? [Y|n] '\'''
read -t 5 -n 1 -p 'Confirm? [Y|n] ': 1: read: Illegal option -t

This thread suggests that sh is invoked in which case there is no -t option to the read built-in.

Given it used to work on my previous laptop ... instead of relying on some workarounds like prepending the alias command with bash -c, is the shell being used here something that can be configured?

Thank you.

like image 457
Stphane Avatar asked Dec 31 '25 11:12

Stphane


1 Answers

In general, on Linux, the way to make sure a particular interpreter runs a particular script—script here meaning commands stored in a file that is marked executable—is to have the file start with #! followed by the path-name of the interpreter. (You can put a single space between the #! and the interpreter, and I normally do.)

In this case that would mean using a script instead of an alias. Name your program git-try, put it in a directory that is on your $PATH, and git try will run your git-try script. You can now have the script start with #! /bin/bash to make sure that it gets run with bash.

If you really want it to be an alias instead of a script, the correct solution is to invoke bash -c, as KamilCuk said in a comment.

(Sometimes interpreters move around, so #! /usr/bin/env python3 is a way to work around the problem of not knowing whether python3 will be in /usr/bin or /usr/local/bin. Since bash is usually in /bin/bash this is less of a problem here.)

like image 77
torek Avatar answered Jan 03 '26 02:01

torek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!