Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

redirect output using '>&' gives an error

Status
Not open for further replies.

lpj

Programmer
Nov 30, 2006
1
US
hi,

a vendor's installation instructions has me execute certain commands on the hp-ux command line like so:

who >& outputfile

or:

ls -l |& tee outputfile

which works fine when typed on the command line.

However if i put those same commands into a shell script, i get this error:

"Generated or received a file descriptor number that is not valid."

The script seems to choke on those ampersands. anyone know why?

thanks!!
 
Hi,

as you probably know, there are several kinds of Unix shell, and syntax is different for them.
It seems your login shell is C shell, aka csh, and your shell script is executed by a Bourne-like shell, sh, ksh or the like.
If you want to use in your script the same syntax as from command line, you have to make sure that your shell script will be executed by C shell. Put this line at the beginning of your script:
#!/usr/bin/csh

hope this helps
 
Alternatively (possibly), have you tried escaping the & with \ as in \&

Alan Bennett said:
I don't mind people who aren't what they seem. I just wish they'd make their mind up.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top