0

Example

Var = '/etc/sysconfig/..'
export Var
bash script1.sh

in another script1

cat $Var

This is my Problem: The variable does not call the file in this path

3 Answers 3

2

Do this:

Var='/etc/sysconfig/..'
bash script1.sh "$Var"

Then in script1.sh:

Var=$1
cat "$Var"

The quotes around "$Var" are required to support paths containing spaces.

Sign up to request clarification or add additional context in comments.

Comments

2

Your variable assignment is wrong, it should be:

Var='/etc/sysconfig/..' 

No spaces around =.

If you want to send in a environment variable for one script only then you can use:

Var='/etc/sysconfig/..' ./my_script.sh

And inside my_script.sh:

printf "%s\n" "$Var"
# Will print /etc/sysconfig/..

If you want to send arguments to my_script.sh do what @JohnZwinck suggested. What I suggested is only to change environment variable and shouldn't be abused to send/receive regular variables to a command.

Comments

0

I think no need to to more thing

script 1

#!/bin/bash
a="/home/example"  ### you can do with export command also export a="/home/example"

sctipt2 ## make effective

. script1; 
cd $a

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.