Invoking a bash shell with an export var


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Invoking a bash shell with an export var
# 1  
Old 10-22-2015
Invoking a bash shell with an export var

Hello all,

How can I invoke the bash shell (via command line) to execute another command by setting an exported environmental variable on the fly (as this env var would be used by the command -another script, the bash would execute).

This needs to be done in one single line as the same would go into a make file to build something.

I hope something like this:
Code:
#/bin/bash "export ABC=pqr" ./my_commandScript_using_the_exportedVarABC

# 2  
Old 10-22-2015
Maybe something like would do the trick:-
Code:
/bin/bash -c "export ABC=pqr ; ./my_commandScript_using_the_exportedVarABC"

Does that help?


Robin
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 10-22-2015
Try:
Code:
ABC=pqr bash ./my_commandScript_using_the_exportedVarABC

or if the script is executable (and has #!/bin/bash as the shebang or if bash is the current shell)
Code:
ABC=pqr ./my_commandScript_using_the_exportedVarABC


Last edited by Scrutinizer; 10-22-2015 at 02:21 PM..
These 2 Users Gave Thanks to Scrutinizer For This Post:
# 4  
Old 10-23-2015
Thanks all!

/bin/bash -c "" seems to work; though I had tried in simple tests and were expecting that ps -aef | grep bash would show another bash. Guess it just executes and goes off.

To give the context, I was looking for this is that we have a make file which calls for autoconf ./configure along with some arguments for the configure script (in a single line). This by-default looks for the gcc compiler where as I want the configure script to take IBM's xlc compiler (my platform being an AIX machine). Somewhere, I came to know that the configure scripts would look for exported value of CC to decide on the compiler to be used in the makefile generated by it.

Hence, I needed to call bash before ./configure and set the environment var CC for the path of the xlc (on the same line); this was to me without luck and made me to look for your help.

Thanks, I'll try once again tomorrow morning and would update across.

Last edited by rbatte1; 10-23-2015 at 09:35 AM.. Reason: Added ICODE tags for calarity
# 5  
Old 10-25-2015
Thanks! That worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

BASH script to export var to env

Hi all I am trying to create a script that takes a password input then writes that to a tmp file and puts that tmp file path in my env as a var. It does everything but export the my env and I am unsure why. I am using Ubuntu 12.4 #!/bin/bash read -s -p "Enter Password: " gfpassword... (5 Replies)
Discussion started by: koikoi
5 Replies

2. Shell Programming and Scripting

Invoking Application in Shell Script

Hi All, I have a scenario : 1. A list of servers naming server21, server 22, server 23 etc. This list of servers is separate for my environments. Env1 has 3 server Env2 has 5 serves Env3 has 10 servers 2. Each server accesses application through which I want to invoke some method. So... (7 Replies)
Discussion started by: ankur328
7 Replies

3. Shell Programming and Scripting

Problem invoking shell script

whats wrong here?! ________________ #!/bin/sh # FILE: clean_dirs # GOAL : To clean up directories used in Oracle processing # LANGUAGE : shell script (sh) # PARAMETERS : Input_File # 11/07/02 acri - modified to cd into the directory so it will... (7 Replies)
Discussion started by: gillraj
7 Replies

4. Shell Programming and Scripting

how can I export an alias and use it in any shell that I want to switch to like bash, ksh

None of the aliases that I set are available if I switch to a different shell. How can I export aliases and make them available in any shell that I switch to like ksh or bash ? I tried these $>alias godata='cd /home/kc/app/data' $>alias -x godata='cd /home/kc/app/data' $>alias |... (2 Replies)
Discussion started by: kchinnam
2 Replies

5. Shell Programming and Scripting

export not working in Bash shell

Hi Friends, I am presently migrating shell scripts writter in KSH to SH.I am stuck at this place and i am not able to find a work around:- Let the script name is x.sh Below are some of the codes in it... export abc=hello export abc=hi export abc=how When i am trying to compile the script ... (6 Replies)
Discussion started by: amit.behera
6 Replies

6. Shell Programming and Scripting

Invoking one shell script from another unix box

Hello All, I have a shell script A which is in one unix box. Also i have a script B in another unix box. Now i'm struggling to find a way to invoke A shell script from B shell script. Is it possible to do this in any way..Request you anybody please help me in this point. Thanks in advance. (6 Replies)
Discussion started by: RSC1985
6 Replies

7. Shell Programming and Scripting

Invoking CGI executable after setenv (in bash)

Hello, I have an executable cgi program that I can run manually from my Linux shell after setting environmental variables on the previous line, like this: setenv QUERY_STRING "workdir=/u/here/there/&nb1=5&nb2=1000" MyExecutable.cgiHow can I imitate this behavior in a bash script? I tried... (11 Replies)
Discussion started by: aplaydoc
11 Replies

8. UNIX for Advanced & Expert Users

Invoking shell script with perl command.

Hi All, I am using the following command to invoke the shell script from a perl command. perl -i.bak -pe'BEGIN { $cmd = "/opt/coreservices/tomcat-5.5.9/bin/digest.sh -a sha"; } s/(password=")(*)/ $1.`$cmd $2|cut -d: -f2|tr -d "\n"` /e ' $CATALINA_HOME/conf/tomcat-users.xml I need... (1 Reply)
Discussion started by: nua7
1 Replies

9. Shell Programming and Scripting

Invoking Shell Script via php

list me commands to invoke a shell script from php once the submit button is clicked in the php page. Requirement is Once a submit button is clicked it should run a script that displays the outcome of the script in a html/php. Please help. Thanks in Advance, BubeshJ (2 Replies)
Discussion started by: bubeshj
2 Replies

10. Shell Programming and Scripting

invoking one shell script from other

hi, i am one day old in shell scritpting. how to invoke one shell script from the other? For eg.i have two shell scripts A.sh and B.sh. Inside A.sh i need to invoke B.sh and the return code of A.sh should be the value returned by B.sh. it would be better if you provide any sample shell... (3 Replies)
Discussion started by: ajay xavier
3 Replies
Login or Register to Ask a Question