Reply
Thread Tools
Posts: 151 | Thanked: 93 times | Joined on Sep 2009 @ sofia, bulgaria
#11
You can also use this:

Code:
> echo $TRE

> ./tre.sh TRE=trep
> echo $TRE        
trep
>
file tre.sh
Code:
#!/usr/bin/env ksh

PID=$PPID
 
echo "Modifying $PID to set $1"
TMPFILE=/tmp/tre.tmp
cat<<EOF >$TMPFILE
attach $PID
call putenv ("$1")
detach
EOF
cat $TMPFILE
gdb -batch -x $TMPFILE > /dev/null
 
rm $TMPFILE
Although I prefer the exec solution more than this one. This requires gdb.
 

The Following 2 Users Say Thank You to lidow For This Useful Post:
Posts: 451 | Thanked: 329 times | Joined on Sep 2009
#12
Originally Posted by lidow View Post
where in script.sh you source environment and then exec bash, will substitute your current shell with the one from the script. This will give you all environments you need, and will not open chain of subshells.
This does exactly what I have in mind...

However, there is the problem that you have to call the script via exec...

I need it to be callable just by a command. If I create a script with:

exec /path/to/script.sh

then when this script is run, it hatches another subinstance of bash in the current term window, instead of replacing it, which is what happens when called with exec directly.

Any way round it.
 
Posts: 151 | Thanked: 93 times | Joined on Sep 2009 @ sofia, bulgaria
#13
alias script="exec script"
 

The Following 2 Users Say Thank You to lidow For This Useful Post:
Posts: 451 | Thanked: 329 times | Joined on Sep 2009
#14
Works on the N900 as well through "exec sh" inside the script.

I want to build a universal script that will exec either bash or sh, depending on which environment it is run.

How do I determine programatically whether exec sh or bash inside a script? An equivalent of `echo $0` ran from within the terminal...
 
Posts: 151 | Thanked: 93 times | Joined on Sep 2009 @ sofia, bulgaria
#15
echo $SHELL
 

The Following 2 Users Say Thank You to lidow For This Useful Post:
Posts: 451 | Thanked: 329 times | Joined on Sep 2009
#16
Duh...

Forgot about this variable, for some reason kept thinking about $TERM and 'no, that's not it'...
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 09:48.