How to change Linux Terminal environment variable in a perl or bash script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to change Linux Terminal environment variable in a perl or bash script?
# 8  
Old 07-26-2013
Quote:
Originally Posted by weichanghe2000
Unfortunately, '1.pl csh -l' will also load .cshrc file again. and all variable including MYVAR var will be recovered as setted in .cshrc.
That's what you asked for. If you don't want it loaded, you may have to live with the limited prompt.
Quote:
Do you have any good ideas suggestion for me?
I have one good idea: Tell me what your perl script is so we can get rid of the perl and turn it into a csh one that can be sourced without creating a new shell.
# 9  
Old 07-26-2013
I have already did a setting of 'setenv LS_BA_STEM LSB_SGE' in .cshrc.

I must modify LS_BA_STEM value for some reason in the perl script in the below and make new value take effect in current Terminal and also the Terminal prompt must keep raw style just as ctm:/home/wch>

I am using the perl script provided by you.

By the way, my requirement is that all these operation should be did in perl script not allowing source a cshell script manually again in terminal after run over 1.pl.

I am very sorry that my perl script is very long and it cannot be converted to cshell at all. The transform is unimaginable.
I think that the perl script transform to cshell script is not a good idea.

You can did a test for following script.

Code:
#!/usr/bin/perl

$ENV{MYVAR}="asdf";

my $shell=shift;
if($shell) {
        exec $shell, @ARGV;
}
else
{
        exec "bash", "-sh";
}

Thanks.
# 10  
Old 07-30-2013
I did indeed test it, before I posted it. There is nothing wrong with the perl program. Nothing can stop csh from setting its own variables except csh.

Perhaps you could modify your tcshrc to set the environment only when not already set instead. That way, you can reload your tcshrc and get your fancy prompt without overwriting the important environment variable.

Code:
if($ENVVAR == "") then
        setenv ENVVAR "whatever"
endif


Last edited by Corona688; 07-30-2013 at 02:32 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing variable from bash to perl script

Hi All, I need to pass a variable from bash script to perl script and in the perl script i am using those variables in the sql query but its giving error : Use of uninitialized value $ENV{"COUNTRYCD"} in concatenation (.) or string at /GIS_ROOT/custom/tables/DBread_vendor.pl line 50. Can ... (6 Replies)
Discussion started by: NileshJ
6 Replies

2. UNIX for Dummies Questions & Answers

Environment variable substitution in Linux make

I know that I can do this in bash ver=${VERSION:-$DEFVERSION} so ver is $VERSION if it's set but $DEFVERSION if $VERSION isn't set I want to do the same thing as a macro in a Makefile and can't get it to work - maybe something like... VER=$(shell ${$(VERSION):-$(DEFVERSION)}) Any help... (1 Reply)
Discussion started by: JerryHone
1 Replies

3. UNIX for Dummies Questions & Answers

How to change colours in Linux Terminal Xfce?

Hi all - just started using Linux Mint 17 and I need to change the Foreground & Background Colours for the Terminal, my eyesight is not what it used to be many years ago, so any help would be much appreciated. Regards Malcolm (6 Replies)
Discussion started by: electrocad
6 Replies

4. Shell Programming and Scripting

How to start a shell script in a terminal console from graphic environment?

Hello. Normally when you double click on the file name, the shell script start in background. If you want to see what is going on, you must open a terminal console and start the shell within the terminal. Is it possible to start directly a shell script in a terminal console from the file... (0 Replies)
Discussion started by: jcdole
0 Replies

5. UNIX for Dummies Questions & Answers

setting a environment variable on linux

I want to set a enviroment variable VDC_DIR to a particular directory. I am doing it as export VDC_DIR=/abc it gets set but when i logout and do relogin than its not there. one way could be setting it in .profile file. but i have seen it on another box where it is not present in... (2 Replies)
Discussion started by: Jcpratap
2 Replies

6. Shell Programming and Scripting

Perl Csh - setenv ENV change environment variable

I have 3 programs, 1 in perl, 2 in csh: call them perl1, csh1 and run.ol I need perl1 to set csh1 variable NOLOG_qsub = "" I need perl1 to run, run.ol run.ol takes the executable and input and outputs to output run.ol#!/bin/csh -f # run.ol executable input output perl1 should... (1 Reply)
Discussion started by: austinj
1 Replies

7. Shell Programming and Scripting

Unable to change environment variables in bash script

Hello! For the moment some settings in my .bashrc contain the password of my company's firewall, which is not a good idea. I would like to use the string "PASSWORD" set in .bashrc and a script that changes all appearances of "PASSWORD" in the environment variables by the actual password (which... (4 Replies)
Discussion started by: markolopa
4 Replies

8. Shell Programming and Scripting

Not able to change the environment variable in k shell

Hi All, I am trying the following to set the environment variable in my scirpt.But it is not setting with the correct value. Can you guys please help me out to get the correct value. 1. I have environment variable NLS_LANG=American_America.UTF8 2. In my script (ksh) i am trying the following... (1 Reply)
Discussion started by: girish.raos
1 Replies

9. Linux

How to create file on Linux using environment variable in the dirpath

Hi all, I am running a Java program on a Linux server in which I read in a base directory path from the *.properties file. During processing, I build a unique file name and create a file to save data, concatenating the directory path and the file name. Works fine, except that I now need to... (2 Replies)
Discussion started by: patricia1of5
2 Replies

10. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies
Login or Register to Ask a Question