Replace literal in .html with Unix

0

I have a series of scripts declared in an html with the following format: xxx.jfhdskfjhdskjfhdskjfjioe3874.bundle.js. The part between the points is a dynamic hash, but it will always be an alphanumeric with the same positions. My problem is that I need to dynamically modify that hash, with the new generated files, which are in the same directory as the html itself. Is there a clean way to do it in Unix with a script?

Thank you!

    
asked by Andres Martin Saldaña 01.03.2018 в 11:12
source

2 answers

0

If you have the possibility to use PHP, you can use this to load the js dynamically, in the html (changing it to php):

<?php
    $ruta = ".";
    $filehandle = opendir($ruta);
    while($file = readdir($filehandle)) {
        if($file != "." && $file != "..") {
            if(substr($file,-3) == ".js") {
                echo "<script type='text/javascript' src='$ruta$file'></script>";
            }
        }
    }
    closedir($filehandle);
?>
    
answered by 01.03.2018 в 16:23
0

Let's see how it is. This changes the name for the hash you give it. I imagine that the idea is to calculate the new hash and modify the name with the new one. Here I take one as if it were already calculated.

   #!/bin/bash

   fichero=xxx.jfhdskfjhdskjfhdskjfjioe3874.bundle.js
   hash2=abcdefghijk1234567890ABCDEFG
   fichero2=${fichero:0:4}$hash2${fichero: -10}
   mv fichero fichero2
    
answered by 23.05.2018 в 17:10