1

How can I echo to stdin?

For example, I have an alias called 'replace'. When I run 'replace' it should echo

sed 's/~/~\\n/g' 

into my command line. Notice the sed command above doesn't have a file target. I'll supply the file target after it echos the sed into the command line.

4

1 回答 1

1

像这样创建alias

alias replace="sed 's/~/~\\n/g' "

然后像这样运行它:

replace file

PS:它不会echo在您的 tty 上使用完整的 sed 命令,但它会有效地运行:

sed 's/~/~\\n/g' file

编辑:关于执行前回显命令的问题。创建一个sedscript.sh这样的脚本:

set -x
# do some sanity check on $1
sed 's/~/~\\n/g' "$1"

现在你有这样的别名:

chmod +x sedscript.sh
alias replace="/path/to/sedscript.sh "

现在每次运行时:

replace file

它会在 sed 命令执行之前回显这一行:

++ sed 's/~/~\\n/g' file
于 2013-08-21T21:47:31.570 回答