2

I would like to set a variable which name is stored in a file (is an output of a sed executed earlier)

the file would look like:
py1
so setting our variable would be like: set cat file=value
but echoing $py1 gives me nothing.

Is that possible with bash version 2.05?

3 Answers 3

3

This is the "preferred" way to do it (bash) without using cat or eval

declare $(<file)=value
Sign up to request clarification or add additional context in comments.

1 Comment

well bash gives me this: declare: Command not found. so i guess i have to use eval
2

Use eval:

eval "$(cat file)=value"

Update: The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).

1 Comment

Yeah, that was simple... haven't heared before 'bout that eval (evil :)) function!Thanks
0

You'll need to use eval

eval $(cat file)=value

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.