我对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=$1
case $1 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发布于 2021-07-23 16:04:18
把那些美元的牌子移走。只有在代码中再次使用这些变量时,才需要添加美元符号。
#!/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=$1
case $1 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
;;
esachttps://stackoverflow.com/questions/68501958
复制相似问题