0

I have two file sh. a.sh b.sh

In a.sh I have something like this:

a=10
sh b.sh $a

echo $a

In b.sh I have

a=$1
if (( 1 > 2 ));
then
   a=20
else
   a=$1
fi

I want to assign $a in a.sh after check condition in b.sh. I try with export but without lucky.

1
  • Have you tried sourcing b.sh from within a.sh? Like, . ./b.sh $a instead of sh b.sh $a Commented Feb 29, 2020 at 12:28

2 Answers 2

1

You can try something like this-

a.sh

a=10
a=$(sh b.sh $a)
echo "From b.sh in a.sh a=$a"

b.sh

x=$1
>&2 echo "Got x = $x in b.sh"
if ((2>1)); then
    echo 20;
fi

Execution -

sh a.sh

Output

Got x = 10 in b.sh ## writing to error stream just for display purpose
From b.sh in a.sh a=20
Sign up to request clarification or add additional context in comments.

Comments

0

If i not wrong you can try like below way.

second.sh :

var = 3
echo"$var"

main.sh:

var = $(./second.sh args...)

1 Comment

better check your syntax at shellcheck.net

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.