Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
- The problem statement, all variables and given/known data:
That is the last reply I received from my instructor, and I'm looking for some alternatives.
When using the trap command, the echo statement does not return to the console. Instead, there are the spaces, which indicates to me that the echo command is recognized but the termial won't display the characters. This is based on 3 weeks of experience.
I've tried this same script in Knoppix and Ubuntu, both of which are clean installed, and the Toolwire virtual environment that the college provides and cannot get this script to echo as such:
This is a test program
Loop #1
Loop #2
Loop #3
^C Sorry! I have trapped Ctrl-C
Loop #4
Loop #5
Loop #6
Loop #7
^C Sorry! I have trapped Ctrl-C
Loop #8
Loop #9
Loop #10
This is the end of the test program
This is a last ditched effort to solve the problem, the instructor and I have been going at this for a couple of days and it's really time to move on. I still want to solve this so I am reaching out to all of you to see if I can get an understanding of the dynamic happening here. Mostly becuase the book says the script works, it works for the instructor and a classmate, just not me.
I hope I have provided enough information. Let me know if I need to post something else such as a screenshot.
Thank you.
2. Relevant commands, code, scripts, algorithms:
Using the script copied from the text:
Ch. 15, �Script Control,� of Linux� Command Line and Shell Scripting Bible.
System Info:
RHEL = ver 6: 2.6.18-348.4.1.el5
Terminal = Gnome gnome-panel 2.16.1
SHELL = bash
VirtualBox = 4.2.12.r84980
- The attempts at a solution (include all code and scripts):
Script
#! /bin/bash
count=1
trap " echo 'I have trapped CTRL-C'" SIGTERM SIGINT
echo "Start of the program..."
while [ $count -lt 10 ]
do
echo "Loop #$count"
sleep 10
count=$[ count + 1]
done
echo "End of the program..."
Output
Start of the program...
Loop #1
# Should Echo Here {^C}
Loop #2
# Should Echo Here {^C}
Loop #3
Loop #4
Loop #5
Loop #6
...echo
Loop #7
...echo
Loop #8
....echo
Loop #9
End of the program...
[me@localhost ~]$ I have trapped CTRL-C <--the trap echos here.
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
University Of Phoenix - Online; Dr. Lori Nicholson; POS 421
Instructor Feedback:
I don't think it has anything to do with you and your code - after I made a few corrections to your script - but I think it may be your system setup.
The trap is captured - that's not the issue. The issue is what happens after the program execution is stopped by the trap. The system will not let it continue one more step and echo out the display to the screen. The trap stops the program but doesn't continue to execute the shell script to the point where we see the text and the echo command is executed.
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).