nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

avoid displaying errors while executing a script

This is a discussion on avoid displaying errors while executing a script within the Shell scripting forums, part of the Development/Scripting category; Hi all, I am running a script on bash shell, although it gives me the desired output, it displays some ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 10-29-2007, 10:22 PM
Member
User
 
Join Date: Oct 2007
My distro: Linux RHEL 5
Posts: 33
Rep Power: 0
vikas027 is on a distinguished road
Red face avoid displaying errors while executing a script

Hi all,

I am running a script on bash shell, although it gives me the desired output, it displays some errors at the prompt like

this directory doesnt exists
unary operator
etc etc


Is there someway to avoid these errors ??
Its very annoying to have these errors while the script is executing.

Thanks
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-29-2007, 11:14 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 917
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Try to redirect output or error device:
Code:
/path/to/command  > /dev/null
Or better:
Code:
/path/to/command >/dev/null 2>&1
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 10-30-2007, 12:02 AM
Member
User
 
Join Date: Oct 2007
My distro: Linux RHEL 5
Posts: 33
Rep Power: 0
vikas027 is on a distinguished road
Unhappy

Quote:
Originally Posted by nixcraft View Post
Try to redirect output or error device:
Code:
/path/to/command  > /dev/null
Or better:
Code:
/path/to/command >/dev/null 2>&1
Its giving error,
I m running

Code:
/home/test/script.sh > /dev/null 2>$1
Reply With Quote
  #4 (permalink)  
Old 10-30-2007, 03:33 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 917
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

It should work...

Code:
rmdir x
rmdir: x: No such file or directory

So I did
Code:
rmdir x > /dev/null 2>&1
No error, you must not put any space between 2>&1 treat it as one word
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #5 (permalink)  
Old 10-31-2007, 11:57 AM
Member
User
 
Join Date: Oct 2007
My distro: Linux RHEL 5
Posts: 33
Rep Power: 0
vikas027 is on a distinguished road
Default

Hi all,

adding this line at top of the code helped

exec 2>/dev/null

Thanks to all.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
cgi script downloads - instead of executing sathiya Ubuntu / Debian 2 06-13-2008 01:14 PM
prelink errors... CentOS 5 ITDevil CentOS / RHEL / Fedora 2 11-13-2007 04:59 PM
Executing .exe files in Red Hat Linux AS4 shilpigoel1 Linux software 1 08-10-2007 07:39 PM
Quick improvements to avoid hacking to a Perl form Script mariolima Coding in General 0 07-10-2007 06:57 PM
displaying the executed command then echo the status warren Shell scripting 4 11-29-2006 01:56 AM


All times are GMT +5.5. The time now is 04:39 AM.


Powered by vBulletin® Version 3.7.3 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36