为什么我随脚本提交的标志会导致 "command not found" 错误

why are the flags I submit with my script causing a "command not found" error

我对 bash 脚本编写还很陌生,但我正在尝试编写此脚本以努力学习 bash / 让我的生活更轻松。标题基本上说明了一切,下面是相关代码的片段。

这是我调用脚本的方式,以及我得到的错误:

[root@vlab024200 ~]# ./vm_setup.sh "vlab024200" "5.0_SP1"
./vm_setup.sh: line 6: =vlab024200: command not found
./vm_setup.sh: line 9: =10.204.128.28: command not found
./vm_setup.sh: line 10: =AC_or_IDP: command not found

除了下面 vm_setup.sh 的片段之外,我还有几条日志消息在日志消息中调用了 $vm。他们省略了 $vm 变量并读取类似于“编辑接口配置文件以作为主机地址”的内容。

作为 bash 的新手,我觉得我对如何在 bash 脚本中实现标志存在根本性的误解。我一直在阅读如何执行我将添加的输入验证,但我找不到任何关于为什么我的脚本没有正确接受我给出的前两个标志的信息。我希望得到有关此脚本的一些帮助,但最终我想了解我做错了什么。

#!/bin/bash
# This script configures the hostname, hosts and interface cfg file.
# After the network is configured the VM is then registered installs
# wget, vim downloads NAM and restarts VM

# define values unique to this machine
$vm=
case  in
    vlab024200)
        $newIP="10.204.128.28"
        $role=AC_or_IDP
        ;;
    vlab024201)
        $newIP="10.204.128.29"
        $role=AC_or_IDP
        ;;
    vlab024202)
        $newIP="10.204.128.30"
        $role=AC_or_IDP
        ;;
    vlab024203)
        $newIP="10.204.128.31"
        $role=AG
        ;;
    vlab034305)
        $newIP="10.204.130.175"
        $role=AG
        ;;
esac

删除那些 $ 符号。仅当您在代码中再次使用这些变量时才需要添加美元符号。

#!/bin/bash
# This script configures the hostname, hosts and interface cfg file.
# After the network is configured the VM is then registered installs
# wget, vim downloads NAM and restarts VM

# define values unique to this machine
$vm=
case  in
  vlab024200)
    newIP="10.204.128.28"
    role=AC_or_IDP
    ;;
  vlab024201)
    newIP="10.204.128.29"
    role=AC_or_IDP
    ;;
vlab024202)
    newIP="10.204.128.30"
    role=AC_or_IDP
    ;;
vlab024203)
    newIP="10.204.128.31"
    role=AG
    ;;
vlab034305)
    newIP="10.204.130.175"
    role=AG
    ;;
esac