Unable to understand [-t 0] inside shell script

bash read options
bash read -r
how to implement error handling in shell script
how to capture error message in shell script
read string in shell script
bash read input
bash read input with spaces
if [ $? -ne 0 ] in shell script

The browser gist by defunkt github user starts with this shell expression

if [ -t 0 ]; then ...

What is the meaning of this line of code?

UPDATE: could you also explain why i need this check before to do anything else?

For the sake of completeness, here is the entire little script (it allow to pipe text to the default browser):

 if [ -t 0 ]; then
  if [ -n "$1" ]; then  
    open $1
    cat <<usage
Usage: browser
       pipe html to a browser

$ echo '<h1>hi mom!</h1>' | browser
$ ron -5 man/rip.5.ron | browser

  cat /dev/stdin > $f
  open $f

Exit Codes - Shell Scripting Tutorial, What is Exit 0 and Exit 1 in shell script? I want to write a shell script that can login to root user and it should carry password inside the same script. It should not ask for password on the terminal. I have written a script that works fine, but it is asking for password on the terminal, I want to automate this process by giving the password inside script only.

From the ksh manual (true for bash too).

-t fildescriptor    
   True, if file descriptor number fildes  is open and associated with a terminal device.

So file descriptor 0, is std input.

Your code asks, essentially, are we running in a interactive mode, or are we in a batch mode.

I hope this helps.

Exception handling in shell scripting?, How do I check if a variable is not empty in bash? Thus, I am unable to start this process in background from inside the shell script. <Path to My application> <options> & The application window opens but makes no progress after that. (The application is a modified(by me) version of qemu 0.13.0. When I run a disk image from that in background in a shell script, I get stuck with a black screen)

This is very useful to check if a shell script is called by a real user using a terminal or if it was called by a crontab or a daemon (in this case the stdin won't exist).

if [ -t 0 ] --->> if there is a stdin connected (normally a keyboard)

What is the difference between exit(0) and exit(1) in C?, Unable to understand [-t 0] inside shell script · Ask Question The browser gist by defunkt github user starts with this shell expression if [ -t 0 ];  How to check for command inside shell script by Milosz Galazka on June 23, 2016 and tagged with Debian , Command-line , Shell script Today, I will illustrate a simple way to check for specific command inside shell script, which is quite simple as it uses only shell built-in command utility.

Why bash "read -t 0" does not see input?, The man read will give the manual of a program in PATH called read . To read bash man page use man bash and search for read [-ers] or simply use: read -t 0 && read -d '' myData [ "$myData" ] && echo "got input" you may be able to reproduce the -t 0 behaviour with something like -t 0.00001 .1). Automate SFTP using shell script with password (Using Expect) Now you can automate SFTP using shell script with password in combination with multiple third party tools such as expect or sshpass. In our example I will show SFTP command example in Unix shell script with password using expect . Step 1: Install Expect on client node

Learn Linux Shell Scripting – Fundamentals of Bash 4.4: A , /dev/null In reality, all data sent (actually, written) to /dev/null will be discarded, but 1 This operation fails (because the reader user obviously can't write in the home directory of the root superuser). ubuntu:~/scripts/chapter_12$ echo $? 0​  FineReader 7.0 Scripting Edition includes extremely fast functions to read popular 1D barcodes and 2D PDF417 barcodes, printed at any angle. This is an ideal function for use in fast document sorting, classification, or pre-processing during bulk document input. User-Friendly Interface and Easy Review and Editing.

Fedora 10 and Red Hat Enterprise Linux Bible, If you were able to boot Fedora or RHEL, you can see how the installation If a service fails to start properly, there may be clues in this file that will help you learn Package Ki t, or rpm 0 Partitioning — f di sk 0 Boot loader — /boot /grub/grub  dyld: Library not loaded in automatically Learn more about standalone, dyld_library_path MATLAB

  • @shelter why do I have to distinguish between interactive and batch inside the script?
  • look at what is happening inside of the block defined between that if [ -t 0 ] ; then .... what is this code doing ... ; fi That is the reason. You may be sourcing rc files that are only meant to load aliases and functions, that are only useful on the command line. (That is the most common use of that test). Contrast that to when you ar running a script from a crontab, there will be no terminal associated with the script. Good luck.
  • Though we thank you for your answer, it would be better if it provided additional value on top of the other answers. In this case, your answer does not provide additional value, since another user already posted that solution. If a previous answer was helpful to you, you should vote it up instead of repeating the same information.