小编Mar*_*mbo的帖子

为什么这个函数不能用于吸收标准输入?

这:

echo 'some text' > file.txt
cat file.txt > file.txt
Run Code Online (Sandbox Code Playgroud)

显然给了我一个空文件。

但也令我惊讶的是:

cat2 () {
    cat "$@" > tmp.txt
    cat tmp.txt
    return $?
}

echo 'some text' > file.txt
cat2 file.txt > file.txt
Run Code Online (Sandbox Code Playgroud)

它给了我一个空文件,即使该文件tmp.txt已被删除,与file.txt.

这个方法也行不通!:

echo 'some text' > file.txt
cat file.txt | cat2 > file.txt
Run Code Online (Sandbox Code Playgroud)

为什么文件还是被清空了?

bash io-redirection

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

sed:-e 表达式 #1,字符 1:未知命令:'|'

当我将此代码放入终端时:

sed -i "|^if [[ -f /etc/skel/.bashrc ]]; then . /etc/skel/.bashrc; fi|d" ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

我获得:

sed: -e expression #1, char 1: unknown command: '|'
Run Code Online (Sandbox Code Playgroud)

为什么?

bash sed shell-script

0
推荐指数
1
解决办法
489
查看次数

标签 统计

bash ×2

io-redirection ×1

sed ×1

shell-script ×1