开发者

When executing a shell script in Ubuntu (or any unix-type enviro) how can I persist exports outside of the script?

开发者 https://www.devze.com 2023-03-04 17:09 出处:网络
I\'m new to Linux and especially to Ubuntu 11 which I\'m just trying today for the first time.I need Linux for some development which requires a Linux-based emulator, so I\'m trying to write a shell s

I'm new to Linux and especially to Ubuntu 11 which I'm just trying today for the first time. I need Linux for some development which requires a Linux-based emulator, so I'm trying to write a shell script that sets up my dev environment.

Now I've created a .scripts folder in my home dir and added it to my path by exporting it in .bashrc so every time I start a new terminal instance, I can execute any custom scripts I drop in there.

Now one (three actually) of those scripts sets up all my dev-related paths, exports, as well as a cd command which switches to the appropriate folder for this dev. How开发者_开发技巧ever (again forgive me if you already know this...) the script runs in its own 'session' (for lack of a better word) so although the enviro-vars and such are all set up and do execute (as was proven by embedding echo calls throughout) when the script finishes and I'm returned back to the terminal where I executed the script, that other session no longer exists and with the exception of clearing the screen and echoing output, there's nothing else showing the script ever ran.

Now I'm not sure its even possible to extend exported variables outside of that script back to the calling 'instance' or of there's some kind of flag I can set to execute the script in the existing session, so I'm stumped.

Now if that is not possible, is it at least possible to write a script or set up an icon that can launch a new terminal window, then execute the script but leaving the window open and initialized?

Thanks!

Mark


Put the script in a function definition in ~/.bashrc. For example

enter_dev_env() {
        cd /home/foo/src
        export foo="bar"
}


Run the command with source.

source foo.sh

0

精彩评论

暂无评论...
验证码 换一张
取 消