3 Replies - 1285 Views - Last Post: 28 May 2012 - 08:39 PM Rate Topic: -----

#1 apaddobs  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 16-May 12

Shell script : 2>&1 confusion

Posted 28 May 2012 - 08:20 PM

Hi,

Within my shell script (#!/bin/sh), when I have
$cmd > a.log 2>&1 &

this does kick off a job in the background.

On the command line, when I run
$cmd > > a.log 2>&1 &
Ambiguous output redirect.

Why is that?
Is This A Good Question/Topic? 0
  • +

Replies To: Shell script : 2>&1 confusion

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5327
  • View blog
  • Posts: 27,246
  • Joined: 10-May 07

Re: Shell script : 2>&1 confusion

Posted 28 May 2012 - 08:23 PM

You have two redirects next to each other in your line of code.

You have cmd, output to, output to, a.log.
Was This Post Helpful? 0
  • +
  • -

#3 apaddobs  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 16-May 12

Re: Shell script : 2>&1 confusion

Posted 28 May 2012 - 08:35 PM

Not sure how this works fine through my shell script. Is it that the shell script is ignoring the second one?

So how do i get the stdout output to a.log, run it as a background process and stderr to say /dev/null?
cmd >& a.log < /dev/null &
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5327
  • View blog
  • Posts: 27,246
  • Joined: 10-May 07

Re: Shell script : 2>&1 confusion

Posted 28 May 2012 - 08:39 PM

The "/dev/null 2>&1" tells the shell to send standard output & standard error to /dev/null, which is a file & basically means don't show output or errors. Now, you can't redirect standard output to both a.log & to /dev/null.

Can you further describe what you are trying to do?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1