1822168 Members
3849 Online
109640 Solutions
New Discussion юеВ

What does &- mean?

 
SOLVED
Go to solution
zhaogui
Super Advisor

What does &- mean?

Hi,
Recently I saw a command line,
remsh remotesp /tmp/test1.sh 2>&- \;/tmp/test2.sh > logfile
can anybody tell me why use "&-" and "\;" here?
Thanks,
19 REPLIES 19
Deepak Extross
Honored Contributor

Re: What does &- mean?

Seems to me that the standard error is being suppressed by the 2>&-

Form the man page of sh-posix(1):
>&- The standard output is closed.
Hartmut Lang
Trusted Contributor

Re: What does &- mean?

From man sh-posix:
>&- The standard output is closed.

\; rest of the line is still part of the remsh command and not a new command of the same shell.

Hartmut
Steven Sim Kok Leong
Honored Contributor
Solution

Re: What does &- mean?

Hi,

0 is the file descriptor for stdin (standard input)
1 is the file descriptor for stdout (standard output)
2 is the file descriptor for stderr (standard error)

2>&1 means redirect stderr to stdout so that all your errors will be redirected to the standard output of your current tty.

&- with > redirects the output be it from stdout or stderr to null ("/dev/null") so that nothing is displayed on your current tty.

>&- or 1>&- redirects the stdout to null.
2>&- redirects the stderr to null.

\; is to dereference the ; symbol so that it will not be interpreted by the shell as a separator between two different command lines. This ensures that ; is treated as part of the command line.

Hope this helps. Regards.

Steven Sim Kok Leong
zhaogui
Super Advisor

Re: What does &- mean?

Can I replace &- with &1? How can I generate logfile on remote machine?
Steven Sim Kok Leong
Honored Contributor

Re: What does &- mean?

Hi,

In general, if you replace &- with &1, then your stderr will be redirected to your stdout which is subsequent redirected to your logfile in your command via >.

Hope this helps. Regards.

Steven Sim Kok Leong
zhaogui
Super Advisor

Re: What does &- mean?

After running this command, I got all the output in local logfile. Even after I changed &- to &1, I also got the same result, why?
How can I create logfile on remote server?
Deepak Extross
Honored Contributor

Re: What does &- mean?

cmd > logfile
will create the logfile on your local host.
To create it on the remote machine, use cmd ">" logfile.
Deepak Extross
Honored Contributor

Re: What does &- mean?

Andreas Voss
Honored Contributor

Re: What does &- mean?

Hi,

the >&2- just closes stderr.
the \; has the effect, that the following commend will be executed remotely. If you ommnit the \ only the first command will be executed remotely.

To get the logfile on the remote machine you only have to escape with \ the redirection:

remsh remotesp /tmp/test1.sh 2>&- \;/tmp/test2.sh \> /tmp/logfile

I recommend to use an absolute path for the logfile to find it easier.

The alternatve is to put all things that has to be remotely in quotes:

remsh remotesp "/tmp/test1.sh 2>& ; /tmp/test2.sh > /tmp/logfile"


Regards
zhaogui
Super Advisor

Re: What does &- mean?

some more scripts
zhaogui
Super Advisor

Re: What does &- mean?

one more
zhaogui
Super Advisor

Re: What does &- mean?

last one
zhaogui
Super Advisor

Re: What does &- mean?

test1
zhaogui
Super Advisor

Re: What does &- mean?

test2
zhaogui
Super Advisor

Re: What does &- mean?

test3
zhaogui
Super Advisor

Re: What does &- mean?

test4
zhaogui
Super Advisor

Re: What does &- mean?

It seems ITRC can not accept zip, tar, gz format. It can only accept .doc or .txt
zhaogui
Super Advisor

Re: What does &- mean?

test2 --binhex
zhaogui
Super Advisor

Re: What does &- mean?

k12 --binhex