0

I want to define variable in shell script as:

value1 = 40  (this can be number or character)

and want to use as in a text like:

$value1_position.xyz (I basically want 40_position.xyz)

How do I do this?

2 Answers 2

1

this should do:

${value1}_position.xyz

beware that the variable should be declared with this syntax

value1=40

notice the absence of spaces around the =

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

1 Comment

Thank you @DRC. I was giving spaces .. Appreciated.
1

To define a variable, simply make sure there are no spaces between the variable name and value

value1=40

To use that variable in bash substitution, creating what you want, use the $ replacement symbol like so:

${value1}_position.xyz

To append that to your text file

echo "${value1}_position.xyz" >> file.txt

1 Comment

Thank you @foips. I was giving spaces. Appreciate your quick answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.