0

I am trying to generate an HTML file with .sh and variable that defined in the shell

     [root@ip-xxx-xx-x-xxx Reporting]: IMAGE_TAG=xyzabc

.sh file code

      #!/bin/bash
      echo "<!DOCTYPE html>" > fargateproductiondeploy.html
      echo "<html> <body>" >> fargateproductiondeploy.html
     echo "<h2>Following Docker container 
     will be deployed  will be Deployed in production up on Approval </h2> 
     <ol>" >> fargateproductiondeploy.html
     echo "<li>$IMAGE_TAG </li>" >> fargateproductiondeploy.html

After running the ./generatehtml.sh out from HTML file was

            Following Docker container will be deployed will be Deployed in 
            production upon Approval 
            1.
1
  • 1
    Does it work if you first do export IMAGE_TAG=xyzabc ? Commented Sep 11, 2018 at 17:06

1 Answer 1

2

You need to export the variable first

$ export IMAGE_TAG=xyzabc
$ ./generatehtml.sh

or source the file

$ IMAGE_TAG=xyzabc
$ . ./generatehtml.sh

Preferable to either would be to pass the value as an argument instead.

#!/bin/bash
image_tag=$1

echo "<!DOCTYPE html>" > fargateproductiondeploy.html
echo "<html> <body>" >> fargateproductiondeploy.html
echo "<h2>Following Docker container will be deployed  will be Deployed in production up on Approval </h2> <ol>" >> fargateproductiondeploy.html
echo "<li>$image_tag </li>" >> fargateproductiondeploy.html

followed by

$ ./generatehtml.sh xyzabc
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.