passing variable to another file and replacing

Hi all,

I have a script in file1 which gets input from the user say variable "TYPE". This variable is present in the other file2. I want to replace the variable in the file2 with the value given by the user and print the file. How can I achieve this task?

file1
code
echo "Give the type"
read TYPE

file two
code
echo "$TYPE"

input
newfile

expected output when I cat the file2

   newfile

Thanks in advance
Ananth

Try parsing the value to the second file..

file1.sh:
#!/bin/sh
echo "Give the type"
read TYPE
./file2.sh	${TYPE}


file2.sh
#!/bin/sh
echo "$1"

Just write after read statement
/usr/bin/sed 's/$TYPE/'$TYPE'/' file2 > file3 and then you can [cat]/print the file.

1 Like

Shukla, Excellent. It worked out. Thanks.