0

I am having a weird problem with bash scripts.

I have two scripts: vlan_menu and the other network_menu. network_menu sources vlan_menu and calls configure_v().

Inside vlan_menu, I do this:

function configure_v() {
    TAG_V=66
    str="team0."
    newtag="$(echo ${str}${TAG_V})"
    ${SCRIPTS}/system_config -e ${newtag} ...
    echo ${newtag} >&2
}

when I run vlan_menu and print the value of ${newtag}, Isee: "team0.66" which is what I want to see.

network_menu:

source vlan_menu
configure_v;

When I run network_menu, the output of the echo is: "team0. 66"

Why does this happen? Please help.

1
  • Your error is not apparent from the snippet you have posted. If there is intervening code between source vlan_menu and configure_v, then it should be posted as well. (see the answer why using command-substitution with echo to assign a concatenated string is wrong -- well, at least, totally unnecessary) Commented May 4, 2016 at 6:06

1 Answer 1

2

You should use the simpler expression:

newtag="${str}${TAG_V}"
Sign up to request clarification or add additional context in comments.

2 Comments

The quotes and braces are both optional as well. newtag=$str$TAG_V is equivalent.
True, but I don't see how that causes the OP's problem.

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.