I believe the discrepancy is due to the inner subshells, i.e. $( ... ) appearing with the same ps output command line as their parent script with later ksh93. One way to filter them out would be to use their parent pid.
Everything you are seeing is what happens when shell scripts depend on shell implementation details which are not prescribed by any standard.
I don't use RHEL and I only have one version of ksh with which to test, but I'm almost certain that the differences that you see between the old and new system is due to a ksh version update and a change in the way those versions execute pipelines/subshells.
If you take a look at the posix standard, it specifies the details of the execution environment, but it says nothing regarding implementation. The reason the command substitutions often yield a number 1 greater than the value from the same command that is not part of a substitution is because the shell has forked another copy of itself to execute the pipeline, and that new copy has the same $0.
The reason you see that 0 in your most recent post is because the shell has most likely exec'd into one of the utilities in its final pipeline before the ps utility fetches the process data. If you add another command after that pipeline, you'll probably see the count remain at 1.
In any case, these scripts make unportable assumptions. Not only are they not portable between different shells, they are not even portable between different versions of the same shell (as you have no doubt noticed ).
The best course of action (unless there is a massively immovable obstacle in the way) would be to rewrite these to not depend on the low level implementation of the shell.
Regards,
Alister
---------- Post updated at 07:15 PM ---------- Previous update was at 06:19 PM ----------
Quote:
Originally Posted by bwhitehd
The last number of the non-patched system is incorrect here. "0" should be "1"
I can reproduce that behavior with the following script (pswc.sh):
KSH Version:
Output:
Also, the trace output confirms that by the time ps starts to read the process list data, all of the ksh instances are gone (exec'd into greps, ps, and wc).
There is nothing "wrong" here, except the expectations of the script.
Hope that helps,
Alister
P.S. I can attach the trace output, but I doubt it's of much interest. It's not a RHEL system (it's not even linux), and you can probably reproduce it yourself with strace (or whatever is the name of the linux equivalent of ktrace).
I agree. I do not like the way that the "developers" write their shell scripts. I'm going to recommend that they change the way they are doing it and move on. I think they were simply counting on an old bug in the previous version.
I have a need to run any number of identical scripts simultaneously, so I've created a driver script which reads a template script, edits these appropriately and then submits them via nohup. The spawned scripts all check to see at some point how many of their number are running and once the count... (7 Replies)
I have a script that reaches out to several systems and pulls back infomation in serveral files. I would like to take the infomation returned and reformat it so I can export it to excel.
Below is current output:
File1:item1:abc=1
File1:item2:efg
File2:item1:ab=1
File2:item2:efg... (3 Replies)
Hello All,
I am trying to change a user passwd (one time password):
cat /tmp/passwd
mnop1234
mnop1234
#passwd abcd < /tmp/passwd
(for some reason, it is not able to input the password from /tmp/passwd and comes back with "New Password: ")
Is there a work around except using "expect".
... (1 Reply)
Suppose, I want to execute unix commands. For that I have to go to ksh, but if I don't have execute permission to ksh itself then is there any way to change the permission of ksh? chmod command does not work for this because, I don't have permission to ksh itself... :)
Let me know, if you have... (3 Replies)
Hi,
I hope I'm posting in the correct forum, so here goes. I would like for the mouse right/left click to work in Terminal (OSX) as it does in Putty.
For instance, when I double click 'log' in file.log.gz, only the log part is highlighted (in Terminal), while in Putty the entire file name is... (0 Replies)
Hi everyone:
Mi default shell is sh, i need to set the TMOUT variable so i need to change the shell to ksh, I change the /etc/profile file as follows, but when i do an echo $0 stll sh been the shell:
# more /etc/profile
#
# (c) Copyright 1990, OPEN SOFTWARE FOUNDATION, INC.
# ALL RIGHTS... (2 Replies)
I'm getting rather frustrated with an interactive script I'm writing.
The script is divided up, with section for setting variable at the top, then functions (which make up most of the script) then basically a line at the end which calls the first function- the program moves between the... (5 Replies)
I am reading a file into a parameter in my program
typeset nums_type
if the contents of nums_type = asdfghbqwerty
how do make a new paremeter eqaul to the 7th character of nums_type.
like
${type} = b (2 Replies)