- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Shell script, different result in different O/...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2007 06:04 AM
тАО06-11-2007 06:04 AM
Can you please let me know what the following script is doing:
#!/usr/bin/ksh
function myFunction {
ls | while read i
do
if [ -d "$i" ]; then
echo "Directory: $i";
elif [[ $i = wp_cancellation*.out ]];
then
echo "Initial Value EmailFlag $EMAILFLAG";
EMAILFLAG=2;
echo "***Altered Value EmailFlag $EMAILFLAG *****wp_cancellation => $i";
fi;
done;
}
WP_IN=/webdata/dev/wp/inbound
cd "$WP_IN";
EMAILFLAG=1;
myFunction
{
echo "Final Value EmailFlag $EMAILFLAG";
}
exit 0
**********************************************
I get the following result, when I run the script on Linux server:
Directory: kris
Initial Value EmailFlag 1
***Altered Value EmailFlag 2 *****wp_cancellation => wp_cancellation20070611112859.out
Final Value EmailFlag 1
***********************************************
But the user complains when he runs the same script on a Tru64 node he gets the following result:
Directory: kris
Initial Value EmailFlag 1
***Altered Value EmailFlag 2 *****wp_cancellation => wp_cancellation20070611112859.out
Final Value EmailFlag 2
I couldn't figure out why???
Any help is greatly appreciated. I know it is nothing related to the O/S issue. But how can I prove to them??
Since Tru64 is going to be end-of-life, we are migrating to Linux environment(node). My question why the final value is different in Linux and Tru64???
Your time is greatly appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2007 06:46 AM
тАО06-11-2007 06:46 AM
Re: Shell script, different result in different O/S???
Linux and Tru64, so you ask about it in an
HP-UX forum? How much sense does that make?
What is "/usr/bin/ksh" on each system?
Perhaps there's a bug in one of the shells.
As I read "man ksh" (on an HP-UX system), I'd
say that the Tru64 result is right, but my
opinion may not be worth much:
[...] Ordinarily,
variables are shared between the
calling program and the function.
However, the typeset special command
used within a function defines local
variables whose scope includes the
current function and all functions it
calls.
[...]
To me, that says that EMAILFLAG is EMAILFLAG,
but I may be missing something. (Similar for
the "{}" around the final "echo".)
You could try a different shell, or change
the script to pass the result differently.
(Use a function return value, for example.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2007 06:56 AM
тАО06-11-2007 06:56 AM
Re: Shell script, different result in different O/S???
I know that i posted in HPUX forms, because I thought u guys respond well and I trust u guys. I always had a good response from this site, thats the reason I posted here thinking that it is not the part of O/S related. It is the part of the script.
Any ways thanks for the time!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2007 10:22 AM
тАО06-11-2007 10:22 AM
Re: Shell script, different result in different O/S???
description of the system, and "ksh" is not a
a complete description of the shell being
used. I tried a slightly modifed version of
your script on an HP TestDrive Linux system
and got the expected result:
td178> /usr/bin/ksh vtx.sh
Directory: fred
Initial Value EmailFlag 1
***Altered Value EmailFlag 2 *****wp_cancellation => wp_cancellation_fred.out
Final Value EmailFlag 2
td178> uname -a
Linux td178.testdrive.hp.com 2.6.18-8.1.4.el5 #1 SMP Fri May 4 22:16:19 EDT 2007
ia64 ia64 ia64 GNU/Linux
td178> /usr/bin/ksh --version
version sh (AT&T Labs Research) 1993-12-28 r
> it is not the part of O/S related. [...]
No, but "ksh" probably came with the OS,
although with Linux, there's always some
doubt where anything came from.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2007 04:21 PM
тАО06-11-2007 04:21 PM
Re: Shell script, different result in different O/S???
Is he complaining that Linux is broken?
Basically Linux is broken. hp-ux's sh, ksh and ksh.93 all agree the answer should be 2.
And as Steven says, the script isn't using typeset to redeclare it.
So you should really redirect this to a Linux thread.
>Steven: (Similar for the "{}" around the final "echo".)
That just makes that execute in the same enironment. It seems that is only useful if you want to redirect the output of a whole block?
I also noticed a whole bunch of wasted ";" on the end of lines.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2007 04:44 PM
тАО06-11-2007 04:44 PM
Re: Shell script, different result in different O/S???
> That just makes that execute in the same enironment.
Exactly, so setting the variable in there
should not cause any trouble.
> I also noticed [...]
It may be that writing the script more
cleanly would lead to better results on the
(mystery) Linux system, but, as I said, it
worked as expected on the first Linux system
I tried, so it'd be too much work for me to
try to find the problem.
True or false: "If you've seen one Linux
system, you've seen them all."
> Since Tru64 is going to be end-of-life,
> [...]
Which is better, an end-of life system which
works, or ...?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2007 04:56 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2007 05:16 PM
тАО06-11-2007 05:16 PM
Re: Shell script, different result in different O/S???
Well, it's 6 years newer than mine (HP's,
actually) _says_ it is.
Tad: Wake up, Tommy.
Tom Reagan: I am awake.
Tad: Your eyes are shut.
Tom Reagan: Who you gonna believe?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2007 06:42 PM
тАО06-11-2007 06:42 PM
Re: Shell script, different result in different O/S???
The way to get it to work is to not use a pipe, but a '<' on the other end of the while:
ls > file
while read i
do
...
done < file
(or if you're BASH happy:
while read i
do
...
done < <(ls)
but I don't think the Tru64 would allow it).
Both 'pdksh' and 'bash' treat piped children in this manner, where as 'ksh' on most other unicies don't.
Either way, the first form here should work on both.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2007 12:13 AM
тАО06-12-2007 12:13 AM
Re: Shell script, different result in different O/S???
Staurt! thank you so much, once I removed pipe and put < it worked. See! I knew I will get answer if I post here.
Steven! See my problem has been solved even though I posted in hp forums. Thank you for your input though.
Dennis! Thanks for your time too..
Still I need to find why the same script doesn't work? when I did #/usr/bin/ksh --version, it says bad option. I also assume ksh is corrupted. Do you how can I download ksh and try???
Thank you all for your time and answers, I really appreciate, this meant alot to me.
Please try to throw some ideas if you guys find something, I am sure u will...;)