Q: force sh to execute profiles?

Q: force sh to execute profiles?

Post by Jochen Kreime » Fri, 18 Apr 1997 04:00:00



Hello,

I would like to open sh that executes the appropriate
profiles on startup like csh does.

Is there any possibility of forcing sh to do so.

Jochen Kreimer
--



 
 
 

Q: force sh to execute profiles?

Post by Brian S Hil » Sun, 20 Apr 1997 04:00:00


: I would like to open sh that executes the appropriate
: profiles on startup like csh does.
: Is there any possibility of forcing sh to do so.
: Jochen Kreimer



Startup script? You mean the 'per-process' initialization script, as in
.cshrc or the $ENV script in ksh? The only way to invoke such a script
in sh is through a hack.

Make the below into file $HOME/.shrc:

# this file (.shrc) needs to be explicitly sourced in
# file .profile, to get the whole process going.
sh ()
{       case $#$1 in
        0|[!0]-*)
                /bin/sh -c 'test -r $HOME/.shrc && . $HOME/.shrc
                exec /bin/sh -i' ;;
        *)      /bin/sh -c "test -r $HOME/.shrc && . $HOME/.shrc

        esac

Quote:}      

# add other commands/initializations here...
echo .shrc is sourced >&2 #XXX
--

If you are familiar with the autoloading feature of ksh and other shells,
here is a function that performs an emulation of this very powerful feature:

#*TAG:51436 4:Jun 21 1996:0700:sh.d/autoload:autoload:

# Bourne shell autoload function: simulate autoload feature found in ksh.
#       Example: autoload foo bar $HOME/shlib/*
# "Autoloading" gives a way to source in externally defined functions
# (defined in files in a known directory by the same basename) and yet
# avoid the shell's overhead at invocation by sourcing in more than needed.
# New feature from ksh autoload: if an argument starts with a "/", FPATH
# is bypassed and the function indicated by it's basename will be called.
# The pathname(s) involved cannot be more than nine directory levels deep.
# Caveat: this needs to be sourced explicitly, before being called itself!
# Caveat: unlike ksh autoload: FPATHs checked for being readable _and_ a file.
# Caveat: this won't work in ksh without first commanding "unalias autoload".
autoload ()
{       _IFS=$IFS : ${1:?'usage: autoload <funct_name|fully_qualified_path>...'}
        for _inst
        do      IFS=/
                set -- $_inst
                eval "case \${$#} in
                [0-9]*|*[!A-Z_a-z0-9]*)
                        echo \"autoload: \${$#}: is not an identifier\" >&2
                        IFS=\$_IFS return 1
                esac"
                IFS=
                case $_inst in
                /*)     [ -f $_inst -a -r $_inst ] || continue
                        eval eval "\"\${$#} () {

                        }\"" ;;
                *)      eval "$_inst () {
                        _IFS=\$IFS
                        if      IFS=:
                                for _inst in \${FPATH:-.} # default FPATH = cwd
                                do      test -f \$_inst/$_inst \
                                        -a -r \$_inst/$_inst && break
                                        test
                                done

                        else    echo '$_inst: not found' >&2
                                IFS=\$_IFS return 1
                        fi }" ;;
                esac
        done
        IFS=$_IFS

Quote:}

--

One would also add this script to the .shrc file. The above is not my latest
version, but it will do the job.

Email me if you need any additional clarification.

-Brian

--
| Brian Hiles


 
 
 

1. forcing sh to read .profile

Hi all,

Is there a way to force sh to read its .profile ?. I would like to
define the PATH in the .profile so that a shell run remotely by rsh
can find the appropriate command. I am running xon, which runs sh on a
remote machine, which in turn runs xterm or other x program. The
problem is that sh doesn't seem to read the .profile where the path to
xterm is defined. The result is that the error "sh: xterm: not found"
is all I get from xon. I would imagine that the sh run by xon is
considered a login shell, but that doesn't seem to be the case since
the .profile is not read. I would like then to force sh to read its
.profile and get the PATH.

Thanks,

Luis
---

http://www-pablo.cs.uiuc.edu/People/tavera

2. Information regarding Networking and Networking Security

3. Execute a sh script under perl and sh: sh script; perl script?

4. loop-6 patch and 2.4.2

5. sh -c executes .profile in current directory

6. Looking for a Linux modem

7. How do I force cron to read .profile

8. make zlilo PLEASE HELP - errors

9. the .profile can't execute at the opening xterm

10. executing .profile without logging in?

11. Remote shell do not execute .profile

12. CDE problem, .profile to execute.

13. .profile wont execute in xterms