Error executing jquery in Bashscript

Asked 2 years ago, Updated 2 years ago, 52 views

When you run the script by inserting the html code into the bash script,

Simple code from which html files are created.

Google charts are also loaded well, but if you just write in jquery, the following error appears.

[root@localhost desktop] #bashtotal_ht.sh 
total_ht.sh: line 162: document: command not found
total_ht.sh: line 162: .table tr td: command not found
total_ht.sh: line 162: v.parentElement: command not found
total_ht.sh: line 162: v.parentElement: command not found

The code you want to insert is as follows.

    $(document).ready(function() {
    $('.table tr td').each(function(i, v){
    if (v.textContent === 'Good') {
      $(v.parentElement).addClass('table-success');
    } else if (v.textContent === 'Vulnerable') {
      $(v.parentElement).addClass('table-danger');
    }
  })  
})

The code below is the bash script (total_ht.sh) that you want to insert the jkey code.

#!/bin/bash
present03=`ls -alL /etc/passwd`

if [ -f /etc/passwd ]
    then
        if [ `ls -alL /etc/passwd | awk '{print $1}' | grep ".rw-r--r--" | wc -l` -eq 1 ]
        then
            result03="Good"
            gct=$((gct+1))
        else
            result03="Vulnerable"
            bct=$((bct+1))
        fi
    fi
cat <<- _EOF_ > "test".html
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
   <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load("current", {packages:["corechart"]});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ["Distinguish", "Item",
          ["Good Ho", $gct",
          ["Vulnerable", $bct]
        ]);

      var options = {
        legend: 'none',
        pieSliceText: 'label',
        title: 'test',
        pieStartAngle: 100,
      };

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));
        chart.draw(data, options);
      }
    </script>
</head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha/css/bootstrap.min.css" rel="stylesheet" />
<body>
<div class="header">
</div>
<div class="container">
    <div id="piechart" style="width: 900px; height: 500px;"></div>
    <table data-row-style="rowStyle" class="table table-bordered table-hover thead-dark thead-inverse">
    <thead>
    <tr>
        <th class="text-center">Number</th>
        <th class="text-center">Name</th>
        <th class="text-center"> Status</th>
        <th class="text-center">Results</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td class="text-center">01</td>
        <td class="text-center">$title01</td>
        <td>$present01</td>
        <td class="text-center">$result01</td>
    </tr>
    <tr>
        <td class="text-center">02</td>
        <td class="text-center">$title02</td>
        <td>$present02</td>
        <td class="text-center">$result02</td>
    </tr>
    </tboby>
    </table>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</body>
</html>
_EOF_

Why do errors appear?ㅠ<

bash script jquery html javascript

2022-09-22 11:58

2 Answers

Of course, there is an error.

This is due to the $ symbol. In shell scripts, the $ symbol is used as a parameter symbol.

You can easily think of it as a reserved symbol (grammar) rather than a typical character.

The bypass method is to process $ as an outputable character by performing a querying process in the shell script.

Simply tie it up with a ''.

Please check the reference link below for more information.

https://wiki.kldp.org/HOWTO/html/Adv-Bash-Scr-HOWTO/quoting.html


2022-09-22 11:58

I think it's because the bash script recognizes it as $(command).

https://askubuntu.com/questions/97050/how-to-escape-and-symbols-in-bash

I think it will be solved if you refer to this question and answer


2022-09-22 11:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.