Reading input piped to a bash script

From: Olle Eriksson (pt00oer_at_student.bth.se)
Date: 10/18/04

  • Next message: Chris Metzler: "Re: How to configure apt to retrieve Packages.bz2?"
    To: debian-user@lists.debian.org
    Date: Mon, 18 Oct 2004 19:51:49 +0200
    
    

    Hi

    Can anyone explain how I can read input to a bash script through a pipe?

    I want to be able to receive input both through a pipe, and through
    parameters to the script. For example:

      echo "blabla" | myscript.sh
    and
      myscript.sh "blabla"

    The script should be able to check whether or not any input is coming
    through the pipe, and if not use $1. I have tried with cat and read but
    they always asks the user interactively if nothing is piped to the
    script.

    Thanks
    Olle

    -- 
    To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org 
    with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
    

  • Next message: Chris Metzler: "Re: How to configure apt to retrieve Packages.bz2?"

    Relevant Pages

    • Re: Bash Script to Handle Race Condition
      ... > I have a Bash script that continuously reads from a pipe and for each ... writes the pipe contents to a new file. ... > condition of trying to ftp a file while it is still being written to. ...
      (comp.unix.programmer)
    • Re: [Multi] Wireless Network Configuration
      ... that, you can see it here, even do it is in spanish, I think you can ... but the bash script is kind of confusing to ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
      (Debian-User)
    • accessing a pipe from TCL and C, hang in `close/exit
      ... I have a TCL shell script which opens a socket to some remote host, ... and opens a read-converter pipe. ... data arrives on the remote host. ... Now I want to close the channel from C++: ...
      (comp.lang.tcl)
    • I can process my mail!
      ... I figured out how to pipe mail to my own scripts! ... the script as an argument. ... that won't confuse boundaries for message text. ... sendmail, but I'm not that interested in sendmail in particular. ...
      (comp.unix.questions)
    • Re: how do i..
      ... On Sun, 2004-08-22 at 18:31, Mr. Oberoi wrote: ... > error results from the program(shell script) to a file. ... scriptname> filename 2>&1 ... the pipe character is used to "chain" the output of the command on ...
      (Fedora)