LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-15-2009, 09:58 AM   #1
Offman
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Rep: Reputation: 0
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?

cheers
 
Old 07-15-2009, 10:13 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Hello Offman

Almost certainly. What do you mean by "properly"?

Best

Charles
 
Old 07-15-2009, 10:14 AM   #3
Offman
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
well if i start it with an application launcher the variables are not set globally. so in another terminal on export they are not listed.
 
Old 07-15-2009, 10:17 AM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

Welcome to LQ!

Quote:
Originally Posted by Offman View Post
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?

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.
 
Old 07-15-2009, 10:20 AM   #5
Offman
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
@onebuck

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...

best
marc
 
Old 07-15-2009, 10:25 AM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

Thanks for clearing up as to what you want to do. You could include the call as a 'alias' within your '.bashrc'.
 
Old 07-15-2009, 10:44 AM   #7
Offman
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
So I simply make an alias to source script.sh and than I put the alias as the command in the application launcher?
 
Old 07-15-2009, 10:57 AM   #8
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

Quote:
Originally Posted by Offman View Post
So I simply make an alias to source script.sh and than I put the alias as the command in the application launcher?
Quote:
#.bashrc
#08-30-06 12:20

# Add bin to path
export PATH="$PATH:$HOME/bin"

# Dynamic resizing
shopt -s checkwinsize

# Custom prompt
#PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

#08-29-06 11:40

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.
 
Old 07-15-2009, 11:35 AM   #9
Offman
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Well I really want to have an icon at the taskbar to quickly run the script. don't want to include all the code in the bashrc.
Is there a way?
 
Old 07-15-2009, 12:36 PM   #10
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

If that's all then just create the script and 'chmod +x' then just point to it with your file manager of choice.
 
Old 07-15-2009, 12:41 PM   #11
Offman
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
@onebuck thanks for the help by the way...
I tried this but then it won't set the variables globally....
 
Old 07-15-2009, 12:53 PM   #12
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

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.
 
Old 07-15-2009, 12:56 PM   #13
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Hello Offman

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.

Best

Charles
 
Old 07-15-2009, 01:05 PM   #14
Offman
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
hi catkin and onebuck,

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!


thanks everyone for the help!
 
Old 07-15-2009, 01:21 PM   #15
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

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;
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ignoring Environment Variables when Starting a BASH Script Garnett Linux - Software 3 09-21-2007 01:00 PM
how can custom application launcher use my environmental variables tacca Linux - Software 1 06-01-2007 02:48 PM
Environment variables for bash htarko Programming 1 09-13-2006 03:57 PM
Bash script environment variables mbjunior99 SUSE / openSUSE 4 12-28-2005 12:40 AM
How do I create application launcher using bash script msgclb Programming 2 01-30-2005 06:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration