lesspipe.sh builds the filter command (with its options/args) in a bash array (cmd) which then gets executed like below:
"${cmd[@]}"
This approach appears to work as long as there are no environment overrides, like so :
ls -lA -G ~/
But bash refuses such an invocation when there are preceding environment overrides, like so :
CLICOLOR_FORCE=1 ls -lA -G ~/
On my machine (macOS), lesspipe.sh was trying to invoke that very command when doing less ~/.
Instead of a directory listing, I was getting an error from bash, along the lines of CLICOLOR_FORCE=1 : Command not found
Note that, though on macOS, I am running a relatively recent version of bash (5.x).
PROPOSED FIX
Just prepend the env command in this case, like so :
if [[ "$cmd" =~ '=' ]]; then # first element contains an equal sign ?
cmd=(env "${cmd[@]}")
fi
NOTE
Both the issue and the proposed fix may independently be checked in an interactive bash shell, as below :
$ cmd=(echo "Hello World") ; "${cmd[@]}" # OK
# Hello World
$ cmd=(SOME_VAR=1 echo "Hello World") ; "${cmd[@]}" # NOK, bash complains
# -bash: SOME_VAR=1: command not found
$ cmd=(env SOME_VAR=1 echo "Hello World") ; "${cmd[@]}" # OK, fixed
# Hello World
ISSUE DESCRIPTION
lesspipe.sh
builds the filter command (with its options/args) in a bash array (cmd) which then gets executed like below:This approach appears to work as long as there are no environment overrides, like so :
But
bash
refuses such an invocation when there are preceding environment overrides, like so :On my machine (macOS),
lesspipe.sh
was trying to invoke that very command when doingless ~/
. Instead of a directory listing, I was getting an error from bash, along the lines ofCLICOLOR_FORCE=1 : Command not found
Note that, though on macOS, I am running a relatively recent version of
bash
(5.x).PROPOSED FIX
Just prepend the
env
command in this case, like so :NOTE
Both the issue and the proposed fix may independently be checked in an interactive bash shell, as below :