1754325 Members
2672 Online
108813 Solutions
New Discussion юеВ

about redirect

 
kamal_15
Regular Advisor

about redirect

hi all
can i redirect error to variable?

EX:
i have a script contain sql statments
can i redirect its error to varible insted
/dev/null
and use this variable later?
thanks
4 REPLIES 4
Alex Lavrov.
Honored Contributor

Re: about redirect

I think redirecting it to some file, will be a better idea. Like /tmp/my_script_err_$$

($$ will get the process id, so it will be unique)
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Tony Scully_2
Valued Contributor

Re: about redirect

Kamal,

You can, but the method Alex mentions might better. If you use a variable, take care with it if the error has spaces in it.

Tony
You CAN do that on HP
Oliver Schmitz
Regular Advisor

Re: about redirect

I do this in a bash script with redirecting it from the /dev/null with

command 2>&1 and vice versa

You can pipe the outpu to a file for example with

$cd DIR >> FILENAME 2>&1

the error output aswell will be put into the file.

Hope this helps for your purposes aswell,

regs

Oliver
Oliver Schmitz
Geoff Wild
Honored Contributor

Re: about redirect

Yes you can:

#!/bin/sh
ERROR=""

ls /doesnotexist >$ERROR 2>&1

echo $ERROR

Rgds...Geoff



Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.