LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2008, 05:15 PM   #1
stympman
LQ Newbie
 
Registered: Oct 2008
Posts: 16

Rep: Reputation: 0
need help with my bash script


In the code below, I am supposed to send singals in. The loop send all output to the /dev/null but when I send the signal in, I need the output from those traps commands to be sent to the screen.

Code:
trap "cd .." 1
trap "pwd; ls -l" 2
trap "ps; sleep 5" 15
i=0
while true
do
      i=`expr $i + 1`
      if [ $i -eq 500 ]
             echo "Hey $USER, I am still runnning"
             THIS LINE WILL GENERATE AN ERROR
             i=o
       fi
done 2> /dev/null > /dev/null &
 
Old 10-20-2008, 07:09 PM   #2
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 573

Rep: Reputation: 61
Looks a lot like homework to me....

I got this to work:-
Code:
#!/bin/bash
trap "cd .." 1
trap "pwd >&2; ls -l >&2" 2
trap "ps >&2; sleep 5" 15
typeset -i i
i=0
while true
do
      i=`expr $i + 1`
      if [ $i -eq 500 ]; then
             echo "Hey $USER, I am still runnning"
             THIS LINE WILL GENERATE AN ERROR
             i=o
      fi
done > /dev/null
I don't understand why you redirected stderr to /dev/null at the end of the while loop, or why you're redirecting stdout for that matter either.

My changes send output from the trap statements to stderr, which I have removed from your redirect syntax at the end of the while loop.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM
Bash script to create bash script jag7720 Programming 10 09-10-2007 07:01 PM
[bash] having trouble debugging this bash script. jons Programming 4 02-08-2007 06:51 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration