Dot sourcing differences in ksh, AIX vs Linux vs Solaris


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Dot sourcing differences in ksh, AIX vs Linux vs Solaris
# 8  
Old 02-08-2014
I now have a theory regarding the three behaviors that Charles reported. The ability to source a function was intended to be used with ksh style functions. These normally create their own scope and by sourcing them they behave like like posix style function.

Charles is defining a posix style function and then is sourcing that. This was not intended to happen. My theory is that AIX is advanced enough to support an early implementation of the function sourcing code. And in this implementation the attempt to source a posix style function is simply ignored.

And my theory continues that users were surprised that some functions could be sourced while other could not. And so, in the spirit of least surprise, ksh was modified to tolerate the sourcing of posix style functions.

The documenation does say that sourcing ksh style function is the feature that was added to ksh. The docs neither allow or prohibit sourcing a posix style function as far as I can see. Whether or not my theory is correct, sourcing a posix style function is an undocumented feature and Charles clearly has seen two different behaviors. I think it would be wise to stick only to the functionality that is explicitly allowed by the documentation.
# 9  
Old 02-08-2014
Note - some versions of Linux had/have /usr/dash which is then symlinked to via /bin/ksh.
dash is NOT ksh. Do you have ksh88 or ksh93 on AIX? ksh88 is what you get as ksh on Solaris 9, 10, 11, by default. FWIW. I cannot be sure at all. But your Linux version appears not to be ksh93. dash was an early thing for Linux to get past the fact that ksh93 was not open source. Cygwin still has it in place of ksh.

Please post the output of (on Linux only):

Code:
ls -l /bin/ksh 
strings /bin/ksh | grep -i version

I don't know enough about AIX to comment on Perderabo's idea - it appears to have merit. IBM tends to be like Apple: everything on the command line has to do be redone/recoded/re-engineered, and then made to comply with POSIX later on.

PS: posting your flavor of Linux might have helped earlier on. Otherwise this was a very good question. Thanks.

Last edited by jim mcnamara; 02-08-2014 at 07:47 PM..
# 10  
Old 02-10-2014
Quote:
Originally Posted by jim mcnamara
Do you have ksh88 or ksh93 on AIX?
"ksh" in AIX is a ksh88 which is unchanged since i work with AIX (v 3.2.3, ~1992), which is pretty long. To get a ksh93 you have to call "ksh93" explicitly.


One question i have for charles, though: why is it necessary to source anything? Why don't you use the "FPATH" variable and put your functions into a common path, similarly to a shared library?

FPATH works like the PATH, but for KornShell functions. put all your functions into separate files named the same as the function: if FPATH is set to "/foo/bar" the file "/foo/bar/boom" will contain the sole function "boom()". I use this for all my scripts in conjunction with a variable "DEVELOP", which switches between a copy of the library in my HOME and the common library. This way i can modify the lib functions without interrupting the production code:

Code:
#! /usr/bin/ksh

if [ -z "$DEVELOP" ] ; then
     . /usr/local/lib/ksh/StdEnv
else
     . ~/lib/StdEnv
fi

.... rest of the script

file /usr/local/lib/ksh/StdEnv contains:

Code:
if [ -z $DEVELOP ] ; then
     FPATH=/usr/local/lib/ksh
else
     FPATH=~/lib/ksh
fi

FOO=bar
...            # and all sorts of other environment settings

In my personal profile "$DEVELOP" is set so that scripts called with my user always use the local copy of the lib (or i unset it to use the common copy), all scripts started with non-personal users have "$DEVELOP" not set and therefore use the common library.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh / AIX - Differences between lists to a text file

This seems pretty simple, but I cant figure it out. I get stumped on the simple things. I am running two commands 1) take a listing a directory of files, and filter out the doc_name (which is in a series of extracted files), and place it in a file. ls -l | awk '{print $9}' | grep... (5 Replies)
Discussion started by: jeffs42885
5 Replies

2. Shell Programming and Scripting

Sourcing Env file with eval works with ksh but not BASH

Hi, I am running this on Redhat 5.10 I have a simple test script called test.sh which has the following contents and it uses the BASH shebang. ------------------------------------------------------------- #!/bin/bash eval `/tmp/filereader.pl /tmp/envfile.txt` echo "TESTPATH=$TESTPATH" ... (28 Replies)
Discussion started by: waavman
28 Replies

3. Shell Programming and Scripting

Manipulating field differences using ksh

I have a list of files that should contain the following Im trying to find the items of interest that are missing from each file and create a csv. cat *.txt | while read file do grep 3500 file | tr '\012' ',' done My problem is this possible output one.txt ... (2 Replies)
Discussion started by: popeye
2 Replies

4. Shell Programming and Scripting

ksh script migration from Solaris to Linux.

We are migrating some scripts (ksh) from Solaris 10 to Linux 2.6.32. Can someone share list of changes i need to take care for this ? Have found few of them but i am looking for a exhaustive list. Thanks. (6 Replies)
Discussion started by: Shivdatta
6 Replies

5. AIX

Aix process CPU differences.

Hi, I'm trying to create a script to catch a process which is consuming high CPU which I have pretty much done but it's just finding the correct place to pull the current CPU for that process. When viewed in Topas it's consuming 99.*% cpu But if I try using ps avg or ps -eo pcpu ... (5 Replies)
Discussion started by: elmesy
5 Replies

6. Solaris

rootsh on Solaris 10 is not sourcing root's .profile

I'm attempting to setup rootsh on Solaris 10 to log the activity of users who require root access. However it does not appear to be sourcing root's .profile file even when run with the '-i' option. I was wondering if anybody else has run into this and might have a solution. Thank you. (9 Replies)
Discussion started by: kungfusnwbrdr
9 Replies

7. UNIX for Dummies Questions & Answers

Guide to differences between Solaris and AIX

I've been more used to Solaris, but am now working on an IBM AIX box, P650 Certain commands like "top" are no longer available. Any ideas on where I can find help on this matter? Christopher Freville Alberquerque, NM (6 Replies)
Discussion started by: Solariums
6 Replies

8. UNIX for Dummies Questions & Answers

script sourcing problem (ksh)

I have a script "abc.sh" in /tmp which has exit 0 as its last line when I run this script from /tmp/xyz/def.sh script as . ../abc.sh then the script executes but the control doesn't return to def.sh script for subsequent commands in def.sh but if I invoke the abc.sh from inside the... (3 Replies)
Discussion started by: rakeshou
3 Replies

9. UNIX for Dummies Questions & Answers

Major differences between AIX, Solaris, HP-UX, Linux

Hi All, I want to know the OS level differences between AIX, Solaris, HP-UX, Linux Apart from the vendor, H/w and command differences, any other significant points. regards, guru Charan (9 Replies)
Discussion started by: gurukottur
9 Replies

10. BSD

OpenBSD sh and ksh differences?

Hi, I am running OpenBSD 3.7, my first attempt with this OS. I noticed that both /bin/sh and /bin/ksh are both really the pdksh. Yet each has its own manpage. I was wondering what are the differences b/w the two programs on OpenBSD. I.e., has the team configured pdksh to function one way if... (3 Replies)
Discussion started by: hadarot
3 Replies
Login or Register to Ask a Question