bash script for environment variables
I know this isn't strictly SuSE but I'd like a spot of help if anyone has the time :) TIA I want to set a couple of environment variables at the beginning of a bash script which then calls some sql scripts and finally I want to unset those variables at the end. The idea is that if the database userid and password are set then I don't have to mention them in the sql scripts and they remain relatively private in my versioning system I googled to a bash tute ( http://pegasus.rutgers.edu/~elflord/unix/bash-tute.html ) and I think I understand it but it ain't working for me. Thanks Mike
On Mon, 2005-04-25 at 20:06 +1000, Mike Dewhirst wrote:
I know this isn't strictly SuSE but I'd like a spot of help if anyone has the time :) TIA
I want to set a couple of environment variables at the beginning of a bash script which then calls some sql scripts and finally I want to unset those variables at the end.
The idea is that if the database userid and password are set then I don't have to mention them in the sql scripts and they remain relatively private in my versioning system
I googled to a bash tute ( http://pegasus.rutgers.edu/~elflord/unix/bash-tute.html ) and I think I understand it but it ain't working for me.
Thanks
Mike
No need to unset them as they are only set for the environment of the running script, not for anything else. -- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998 "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners." -Ernst Jan Plugge
Ken Schneider wrote:
On Mon, 2005-04-25 at 20:06 +1000, Mike Dewhirst wrote:
I know this isn't strictly SuSE but I'd like a spot of help if anyone has the time :) TIA
I want to set a couple of environment variables at the beginning of a bash script
Ken - thanks for your response. My remaining question is - how do I set them? Googling indicated this should work ... #!/bin/bash setenv ISC_USER xyz setenv ISC_PASSWORD 999ans ... but it returns setenv command not found. Looking at the man entry it seems setenv is a function to be called from a program. Is there an equivalent which can be called from a script? Thanks Mike which then calls some sql scripts and finally I want to
unset those variables at the end.
The idea is that if the database userid and password are set then I don't have to mention them in the sql scripts and they remain relatively private in my versioning system
I googled to a bash tute ( http://pegasus.rutgers.edu/~elflord/unix/bash-tute.html ) and I think I understand it but it ain't working for me.
Thanks
Mike
No need to unset them as they are only set for the environment of the running script, not for anything else.
On Monday 25 April 2005 15:11, Mike Dewhirst wrote:
Ken - thanks for your response. My remaining question is - how do I set them? Googling indicated this should work ...
#!/bin/bash setenv ISC_USER xyz setenv ISC_PASSWORD 999ans
... but it returns setenv command not found. Looking at the man entry it seems setenv is a function to be called from a program. Is there an equivalent which can be called from a script?
setenv is for C-shell. In bash, use 'export'. export ISC_USER=xyz export ISC_PASSWORD=999ans
On Mon, 2005-04-25 at 15:25 +0200, Anders Johansson wrote:
On Monday 25 April 2005 15:11, Mike Dewhirst wrote:
Ken - thanks for your response. My remaining question is - how do I set them? Googling indicated this should work ...
#!/bin/bash setenv ISC_USER xyz setenv ISC_PASSWORD 999ans
... but it returns setenv command not found. Looking at the man entry it seems setenv is a function to be called from a program. Is there an equivalent which can be called from a script?
setenv is for C-shell. In bash, use 'export'.
export ISC_USER=xyz export ISC_PASSWORD=999ans
But export is not necessary unless you are calling another script that you want to pass variables to, perhaps I am wrong. -- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998 "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners." -Ernst Jan Plugge
Ken Schneider wrote:
On Mon, 2005-04-25 at 15:25 +0200, Anders Johansson wrote:
On Monday 25 April 2005 15:11, Mike Dewhirst wrote:
Ken - thanks for your response. My remaining question is - how do I set them? Googling indicated this should work ...
#!/bin/bash setenv ISC_USER xyz setenv ISC_PASSWORD 999ans
... but it returns setenv command not found. Looking at the man entry it seems setenv is a function to be called from a program. Is there an equivalent which can be called from a script?
setenv is for C-shell. In bash, use 'export'.
export ISC_USER=xyz export ISC_PASSWORD=999ans
But export is not necessary unless you are calling another script that you want to pass variables to, perhaps I am wrong.
Ken I wasn't very clear with my original question so please accept my apology - but that is exactly what I want to do. The bash script sets the user and password vars then calls a series of sql scripts to create a database and make tables, populate some and do other stuff. Everything you do with the database needs those two vars. The sql scripts have to be versioned during development because they will gain more and more detail until they can be used in production. It would be poor practice to store userid and password in a source control management system so I want to just call an environment var from each sql script. Thanks again Mike
On Mon, 2005-04-25 at 23:49 +1000, Mike Dewhirst wrote:
Ken Schneider wrote: Ken
I wasn't very clear with my original question so please accept my apology - but that is exactly what I want to do. The bash script sets the user and password vars then calls a series of sql scripts to create a database and make tables, populate some and do other stuff. Everything you do with the database needs those two vars.
The sql scripts have to be versioned during development because they will gain more and more detail until they can be used in production. It would be poor practice to store userid and password in a source control management system so I want to just call an environment var from each sql script.
Thanks again
Mike
The other thing you can do is have the script ask for the info, that way you don't need to store them inside of the script. It has been a long time since I wrote any scripts but it can be done. Perhaps someone else on the list can help with that part. -- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998 "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners." -Ernst Jan Plugge
Ken Schneider wrote:
On Mon, 2005-04-25 at 23:49 +1000, Mike Dewhirst wrote:
Ken Schneider wrote: Ken
I wasn't very clear with my original question so please accept my apology - but that is exactly what I want to do. The bash script sets the user and password vars then calls a series of sql scripts to create a database and make tables, populate some and do other stuff. Everything you do with the database needs those two vars.
The sql scripts have to be versioned during development because they will gain more and more detail until they can be used in production. It would be poor practice to store userid and password in a source control management system so I want to just call an environment var from each sql script.
Thanks again
Mike
The other thing you can do is have the script ask for the info, that way you don't need to store them inside of the script. It has been a long time since I wrote any scripts but it can be done. Perhaps someone else on the list can help with that part.
Now that would be nice. I could safely put the bash script under version control too :) Mike
Ken, On Monday 25 April 2005 06:32, Ken Schneider wrote:
...
export ISC_USER=xyz export ISC_PASSWORD=999ans
But export is not necessary unless you are calling another script that you want to pass variables to, perhaps I am wrong.
Exporting does not distinguish scripts from other programs. Unexported variables only exist in the shell that defined them. Exported variables are seen by all processes created by that script, whether directly or indirectly (unless an intervening process removes them from the environment before launching a sub-process).
Ken Schneider
Randall Schulz
Thank you Anders - exactly what I want. Thank you George - I didn't need a clean environment - this time :) Regards Mike Anders Johansson wrote:
On Monday 25 April 2005 15:11, Mike Dewhirst wrote:
Ken - thanks for your response. My remaining question is - how do I set them? Googling indicated this should work ...
#!/bin/bash setenv ISC_USER xyz setenv ISC_PASSWORD 999ans
... but it returns setenv command not found. Looking at the man entry it seems setenv is a function to be called from a program. Is there an equivalent which can be called from a script?
setenv is for C-shell. In bash, use 'export'.
export ISC_USER=xyz export ISC_PASSWORD=999ans
On Mon, 2005-04-25 at 23:11 +1000, Mike Dewhirst wrote:
Ken Schneider wrote:
On Mon, 2005-04-25 at 20:06 +1000, Mike Dewhirst wrote:
I know this isn't strictly SuSE but I'd like a spot of help if anyone has the time :) TIA
I want to set a couple of environment variables at the beginning of a bash script
Ken - thanks for your response. My remaining question is - how do I set them? Googling indicated this should work ...
#!/bin/bash setenv ISC_USER xyz setenv ISC_PASSWORD 999ans
... but it returns setenv command not found. Looking at the man entry it seems setenv is a function to be called from a program. Is there an equivalent which can be called from a script?
ISC_USER=xyz ISC_PASSWORD=999ans As I said, look through scripts that are on your system. You will find examples of many different things you will need to use. You may want to buy a book on shell scripting as well. -- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998 "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners." -Ernst Jan Plugge
Mike Dewhirst wrote:
I know this isn't strictly SuSE but I'd like a spot of help if anyone has the time :) TIA
I want to set a couple of environment variables at the beginning of a bash script which then calls some sql scripts and finally I want to unset those variables at the end.
'man env' env -i FOO=BAR and BAZ=BONG will give you a clean environment with only those two variable and should chop them at the end. Cheers, George -- George Barnett Reality Engineer m: (+44) 778 884 7205 e: george@alink.co.za There once was an old man from Esser, Who's knowledge grew lesser and lesser. It at last grew so small, He knew nothing at all, And now he's a College Professor.
participants (5)
-
Anders Johansson
-
George Barnett
-
Ken Schneider
-
Mike Dewhirst
-
Randall R Schulz