小编Joh*_*nes的帖子

GNU Makefile 中的进程替换

在 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)

这是什么意思,有没有办法在不使用临时文件的情况下仍然区分两个输出?

shell bash make process-substitution

13
推荐指数
1
解决办法
2863
查看次数

Bash 完成覆盖当前单词

我正在尝试为我的命令创建一个 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)

bash autocomplete

5
推荐指数
1
解决办法
434
查看次数

标签 统计

bash ×2

autocomplete ×1

make ×1

process-substitution ×1

shell ×1