Get the name of the current terminal

The tty command display the file name of the terminal connected to standard input. Type the following command:

tty

Sample outputs:

/dev/pts/0

OR

/dev/tty1

In this example, tar command will run, only if standard input is a terminal. Create a shell script called termtest.sh:

#!/bin/bash# termtest.sh: Run the tar command only if command run from a termina
tty -sstatus=$?if[$status-eq0]thenecho"Running backup using tar command..."# tar cvf /dev/st0 /homeelse
logger "$0 must run from a terminal"fi