这:
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)
为什么文件还是被清空了?
当我将此代码放入终端时:
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)
为什么?