相关疑难解决方法(0)

在bash中检查isatty

我希望我的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)

bash shell

16
推荐指数
3
解决办法
7019
查看次数

如何在必要时分页git输出

有没有办法配置git 只有当它超过终端大小(或至少一个特定的行数)时才将其输出管道输送到纸张中?我觉得相当讨厌,例如在寻呼机中显示6行差异 - 隐藏任何先前的输出,并要求我明确按"q"退出.

git

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

标签 统计

bash ×1

git ×1

shell ×1