【问题标题】:command not found on shell script run在 shell 脚本运行时找不到命令
【发布时间】:2022-08-17 19:09:55
【问题描述】:

我有一个比较堆内存的脚本

#!/bin/bash

$a=$(jcmd `jps -l | grep com.adobe.coldfusion.bootstrap.Bootstrap  | cut -f1 -d \' \'` GC.heap_info | awk \'NR==2 {print $5}\')

$b=1000000K

if [[ $a -ge $b ]]

 then

   echo \"The heapmemory used is greater.\"

else

   echo \"The heapmemory used is small.\"

fi

我的问题是当我使用./testscriptforheap.sh 执行这个脚本时,虽然输出是正确的,但是为什么我在第 2 行和第 3 行中找不到这个命令,我无法弄清楚。

> ./testscriptforheap.sh: line 2: =1603644K: command not found

> ./testscriptforheap.sh: line 3: =1000000K: command not found 

使用的堆内存更大。

    标签: bash shell ubuntu


    【解决方案1】:

    bash(以及 sh)中的分配不要在它们前面使用$:

    a=$(jcmd `jps -l | grep com.adobe.coldfusion.bootstrap.Bootstrap  | cut -f1 -d ' '` GC.heap_info | awk 'NR==2 {print $5}')
    
    b=1000000K
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 2013-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多