在 bash 提示符下,可以使用伪文件执行 diff:
diff <(echo test) <(echo test)
Run Code Online (Sandbox Code Playgroud)
将其按原样添加到 Makefile 失败:
all:
diff <(echo test) <(echo test)
Run Code Online (Sandbox Code Playgroud)
错误(提示:/bin/sh 指向此系统上的 /bin/bash):
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `diff <(echo test) <(echo test)'
Run Code Online (Sandbox Code Playgroud)
这是什么意思,有没有办法在不使用临时文件的情况下仍然区分两个输出?
我正在尝试为我的命令创建一个 bash 完成脚本。ls
有我想要的行为。我需要从我的命令中获得相同的行为。
这就是我得到的 ls
$ ls /home/tux/<Tab><Tab>
Downloads Documents Pictures
$ ls /home/tux/Do<Tab><Tab>
Downloads Documents
Run Code Online (Sandbox Code Playgroud)
即 bash 只相对地显示下一个路径,而不是绝对地(即它确实添加Downloads
到完成列表中,但不是/home/tux/Downloads
)
我想编写一个以相同方式工作的完成脚本。这是我尝试过的。
_testcommand ()
{
local IFS=$'\n'
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -o bashdefault -d -- "$cur") )
if [ "${#COMPREPLY[@]}" -ne 1 ]
then
# remove prefix "$cur", so the preview of paths gets shorter
local cur_len=$(echo $cur | sed 's|/[^/]*$||' | wc -c)
for i in ${!COMPREPLY[@]}
do
COMPREPLY[$i]="${COMPREPLY[i]:$cur_len}"
done
fi
return 0
}
complete …
Run Code Online (Sandbox Code Playgroud)