sprawdź isatty w bash
Chcę, aby moja powłoka wykryła czy ludzkie zachowanie, a następnie pokaż monit.
Załóżmy, że nazwa pliku to test.bash
<code>#!/bin/bash if [ "x" != "${PS1:-x}" ] ;then read -p "remove test.log Yes/No" x [ "$x" = "n" ] && exit 1 fi rm -f test.log </code>
Ale okazało się, że nie działa, jeśli nie ustawiłem PS1. Czy jest lepsza metoda?
moje metody testowe:
<code>./test.bash # human interactive ./test.bash > /tmp/test.log # stdout in batch mode ls | ./test.bash # stdin in batch mode </code>