top's exit code indicates error--is this a bug?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting top's exit code indicates error--is this a bug?
# 8  
Old 08-12-2008
Quote:
Originally Posted by Perderabo
What kind of shell lets you set an environment variable like that? With sh you need to export it or set it on the command line.
I thought that if you did not export an "environment variable" when you change its value, then the change is only local, that is, the change is only seen within the process that performed that change. Since I execute the top command inside the process that set CPULOOP=1, I would have thought that top would see this new value.

Is this not the way that unix shells typically work? If not, then my experience with normal languages' scoping rules has led me astray.

Note that even if I do
Code:
export CPULOOP=1
top -b -n 1 -U $USER

I still get an error exit code, so I will still file a bug report.
# 9  
Old 08-12-2008
Quote:
Originally Posted by fabulous2
I thought that if you did not export an "environment variable" when you change its value, then the change is only local, that is, the change is only seen within the process that performed that change.
Precisely correct... "only...the process".

Quote:
Originally Posted by fabulous2
Since I execute the top command inside the process that set CPULOOP=1, I would have thought that top would see this new value.
top is not a command built-in to the shell. The shell must fork() a copy of itself and then that copy must exec() the top command. During the exec, the code for top, in effect, overlays the code for the shell. But a very few things are saved and environment variables are one. Regular variables are not saved.

Meanwhile the parent shell is waiting for its child process to finish. It continues to know that CPULOOP is 1. When you put an & on the end on the line, the parent shell does not wait.. it just keeps going.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Can't find the bug in my code - bombing with rename

Hi Folks - I'm encountering an issue: Scenario: We have automated GL data loads utilizing FDMEE. The problem is that some of our Locations could have multiple files. I think we are running into a situation where the script is trying to name the 2 files the same name and it is bombing out.... (8 Replies)
Discussion started by: SIMMS7400
8 Replies

2. Shell Programming and Scripting

Exit code

can anyone tell what the exit status - 137 belongs in unix shell scripting. (3 Replies)
Discussion started by: ramkumar15
3 Replies

3. Programming

Algorthm bug of my code

Hello, This porblem bugged me for some time. It is to merge different files of hundred rows to have a union with the ID as key column (kind of similar to join!) and absence with 0. ID File1 A 1 C 3 D 4 M 6 ID File2 A 5 B 10 C 15 Z 26 ID File3 A 2 B 6 O 20 X 9 I want the output... (9 Replies)
Discussion started by: yifangt
9 Replies

4. UNIX for Advanced & Expert Users

How to Make Sql Plus Exit with an Error Code

Dear all, How to make sqlplus command to exit with an apt error code in bash script, It always returns 0 for me. Thanks (9 Replies)
Discussion started by: vetrivendhan
9 Replies

5. UNIX for Dummies Questions & Answers

Exit TOP command after 1 min

Hi, I am running following command: top -p <psid> | grep used I want to send o/p of above command to some txt file but it do not break as it keeps going. How can I exit 'top -p <psid> | grep used' after certain time like 1 min or 2 mins? (1 Reply)
Discussion started by: sach253
1 Replies

6. Shell Programming and Scripting

Can anyone find a bug in this code?? shell script

I have done a script and IT WORKS JUST PERFECT from command line...but in cron it has problems executing... nawk -F"|" ' { s=substr($104,2,18)} {b ++s} END { for (i in b) print i, b } ' $1 > /path/to/files/TranId_w$2 q=`cat /path/to/files/TranId_w$2 | wc -l` echo $q >... (1 Reply)
Discussion started by: amon
1 Replies

7. UNIX for Dummies Questions & Answers

Where can I find a list of exit codes? (Exit code 64)

I'm receiving an exit code 64 in our batch scheduler (BMC product control-m) executing a PERL script on UX-HP. Can you tell me where I can find a list of exit codes and their meaning. I'm assuming the exit code is from the Unix operating system not PERL. (3 Replies)
Discussion started by: jkuchar747
3 Replies

8. Shell Programming and Scripting

All about exit code

Hi, I am working on Solaris 8 and the "intro" man page says, "Upon termination, each command returns two bytes of status, one supplied by the system and given the cause for termination, and (in the case of 'normal' termination) one supplied by the program. The former byte is 0 for normal... (2 Replies)
Discussion started by: cdin2
2 Replies
Login or Register to Ask a Question