我希望我的shell检测人类的行为,然后显示提示.
因此,假设文件名是test.bash
#!/bin/bash
if [ "x" != "${PS1:-x}" ] ;then
read -p "remove test.log Yes/No" x
[ "$x" = "n" ] && exit 1
fi
rm -f test.log
Run Code Online (Sandbox Code Playgroud)
但是,如果我没有设置PS1,我发现它无法工作.有更好的方法吗?
我的测试方法:
./test.bash # human interactive
./test.bash > /tmp/test.log # stdout in batch mode
ls | ./test.bash # stdin in batch mode
Run Code Online (Sandbox Code Playgroud) 有没有办法配置git 只有当它超过终端大小(或至少一个特定的行数)时才将其输出管道输送到纸张中?我觉得相当讨厌,例如在寻呼机中显示6行差异 - 隐藏任何先前的输出,并要求我明确按"q"退出.