Apollo
Apollo

Reputation: 9054

Accessing Environment Variable in Shell Script

I'm trying to create a shell script that sets an environment variable and then calls another shell script which gets that environment variable. The following code is my attempt, but it's not producing the desired result...

scriptOne.sh

export MYVAR=blob                                                            
bash ./scriptTwo.sh

scriptTwo.sh

#!/bin/bash                                                                     
# SIMPLE                                                                        

printenv MYVAR <<END                                                            
ls || pwd && ls                                                                 
ls || ls | wc || pwd && ls                                                      
END                                                                             
echo

Upvotes: 1

Views: 123

Answers (1)

ShellFish
ShellFish

Reputation: 4551

Try $MYVAR in scriptTwo.sh you need to add a dollar to expand a shell variable. I think you can call it using simply $ bash scriptTwo.sh btw.

Upvotes: 2

Related Questions