Input file : input.txt


"Another file name : output.sh"


I want to copy the value of variables l1,l2 from input.txt to a file variable l1,l2 of file output.sh

  • 1
    As the question is described, the following answer your question: cp input.txt output.sh - did I answer your question? if not - please update your question to describe the problem in a better way. – Yaron Jul 18 '18 at 13:55
  • i am trying that only R2 should stored in the variable l1, the way you told will copy all the contents of input file in output.sh – sj17 Jul 18 '18 at 13:59
  • I want only the value of variable i.e text between " " to go into another file of same variable – sj17 Jul 18 '18 at 14:01
  • What is "a file of that variable"? – L. Scott Johnson Jul 18 '18 at 14:02

If you need to output.sh to accomplish the assignments given in input.txt, you could source the input file

So this would be the content of output.sh

l1="" # not needed
l2="" # not needed
source input.txt

This produces what you want (a value in l1 of R2):

$ cat - > input.txt <<EOF
> l1="R2"
> l2="R1"
$ cat - > output.sh <<'EOF'
> l1="" # not needed
> l2="" # not needed
> source input.txt
> echo $l1
$ sh output.sh
  • no its not working – sj17 Jul 18 '18 at 14:08
  • @ShubhamJain in what way? what should it do? What result are you trying to achieve? – L. Scott Johnson Jul 18 '18 at 14:33
  • after running your soultion , then also my variable value is same as before,there is no value in variable l1 – sj17 Jul 18 '18 at 14:36
  • It works. I've added the shell output that shows that it produces the desired value in l1. Please describe completely what you want to do that this isn't doing or show completely what you are doing that doesn't work. – L. Scott Johnson Jul 18 '18 at 14:51
  • Yes it worked for me also now, i was doing it wrong. tysm for help – sj17 Jul 18 '18 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.