bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Output redirection?


From: Bob Proulx
Subject: Re: Output redirection?
Date: Sat, 28 Jan 2006 20:31:08 -0700
User-agent: Mutt/1.5.9i

Yuri Karlsbrun wrote:
> I, probably, need bash-help mailing list, but I could not find it.
> 
> Here is the bash script fragment:
> LOG_FILE="./logfile"
> ...
> >$LOG_FILE
> 
> I supposed that the statement above redirects stdout to the logfile.
> But the following 'echo' statement prints on the screen. The logfile is
> opened. What is the real purpose of the statement above?

A single line with "> FILE" redirects that line's command to the
file.  You did not have a command and so it just created file and put
nothing into it.  This is exactly equivalent to "true > FILE" or more
idiomatically ": > FILE".

What you are asking to do you would do with the exec command.

Either:
  exec >$LOG_FILE
Or:
  exec >$LOG_FILE 2>&1
Or:
  exec >$LOG_FILE 2>&1 </dev/null

Here are some docs:

  help exec

  exec: exec [-cl] [-a name] file [redirection ...]
      Exec FILE, replacing this shell with the specified program.
      If FILE is not specified, the redirections take effect in this
      shell.  If the first argument is `-l', then place a dash in the
      zeroth arg passed to FILE, as login does.  If the `-c' option
      is supplied, FILE is executed with a null environment.  The `-a'
      option means to make set argv[0] of the executed process to NAME.
      If the file cannot be executed and the shell is not interactive,
      then the shell exits, unless the shell option `execfail' is set.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]