[SOLVED] Bash script with environment variables -Application launcher
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Bash script with environment variables -Application launcher
Hi
I have a bash script where I use EXPORT to set some environment variable. I know if I source it or call it like this ". ~/shellscript.sh" it will set these variables globally.
But is there a way of creating an application launcher for this so it sets the variables properly?
I have a bash script where I use EXPORT to set some environment variable. I know if I source it or call it like this ". ~/shellscript.sh" it will set these variables globally.
But is there a way of creating an application launcher for this so it sets the variables properly?
cheers
Maybe you should look at creating a '.bashrc' & '.bash_profile' for your user.
Do a search here on LQ as I know this very subject has been covered many times.
thanks for the reply.
However, I do not want to include the variables in the bashrc. I am using a virtual machine on different networks and machines. And I wrote a script that mounts the shared folders and sets the network setting according to where it is used. The script already gets called by bashrc but I really prefer to have an application launcher so I can set it up myself. If everytime I open a terminal the script runs it will be quiet annoying with the scripts...
if [ `id -un` = root ]; then
PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
else
PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
fi
#
# Add color
eval `dircolors -b`
# User defined aliases
alias cls='clear'
alias clls='clear; ls'
alias ll='ls -l'
alias lsa='ls -A'
alias lsg='ls | grep'
alias lsp='ls -1 /var/log/packages/ > package-list'
alias na='nano'
alias web='links -g -download-dir ~/ www.google.com'
#07-15-09 10:55
alias some='export PATH="$PATH:$HOME/bin/some"' <<<<- is this OK?
#08-29-06 11:50
#To clean up and cover your tracks once you log off
#Depending on your version of BASH, you might have to use
# the other form of this command
trap "rm -f ~$LOGNAME/.bash_history" 0
#The older KSH-style form
# trap 0 rm -f ~$LOGNAME/.bash_history
What about setting the 'alias' as exampled above? You could tweak and include a conditional but the general idea is to have the path set to a specific environment. You could clear that same 'some' at completion. Just a simple thought.
When you say globally are you wanting system wide settings for all users?
Let's be specific. I keep getting bits of information from your posts. Layout exactly what you are attempting. What exactly are you launching? Is this a trade secret?
Really it may be something as simple as setting up your profiles.
If I understand correctly what you want to do it's impossible, based on how *n*x processes work. Each child process inherits environment variables from its parent, thus it is not possible (and not desirable!) for a child process to somehow inject environment variables into all (you did say "global") processes.
I guess there's something you want to do and you have assumed that the solution is to set environment variables globally. Maybe better to re-wind and tell us what you want to achieve.
I managed to rewrite my script to be a bit more clever. so now it is really only doing the work if necessary and thus it is ok that it runs each time in bashrc.
...what I wanted to do:
I have a vmware virtual machine with ubuntu on a small portable drive. I use this vm on a Windows Vista and a fedora core box. One is at home and needs no proxy etc the other at work need specific settings and proxys. also the paths to the shared folders are different on both systems. so now i have written a script which checks whether mounting is ok and if not it does it according to the system the vm is running on. also it checks whether it is the work or home network and does the job. at the beginning it was very simple and did it's job without checking whether there is anything to do and thus it was annoying to have it run each time the .bashrc is read. no it is ok. also one problem was that sometimes I just resume the vm and thus I have to find an easy way to adapt the settings. so now i simply have to bring up a terminal and it does the trick...
thats it!
It would have been much easier if you had explain what you were attempting to begin with. Read the drift of the thread and you will see how bits of information was provided.
Now you are speaking about a 'VM'. Important information there.
I'm glad you got things working for you.
Please mark the thread solved via the thread tools.
The second link below would be helpful to you for future posts;
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.