我正在尝试创建一个脚本来创建我的虚拟机上的虚拟群集,这是一个最小的CentOS 7。
我得到一个名为cluster的脚本

#!/bin/bash

function vc
{
    echo
    echo -n "Enter project name: "
    read platform_name

    echo
    echo -n "web extension: "
    read web_extension

    echo
    echo -e "The following website will be created"
    echo -e "\e[32m Platform:\e[0m\t${platform_name}"
    echo -e "\e[32m Extension:\e[0m\t${web_extension}"
    echo -e "\e[32m Full URL:\e[0m\t http://www.${platform_name}.${web_extension}"

    echo
    echo -e "Do you wish to proceed? [Y/n]"
    read -p "Are you sure? " -n 1 -r
    echo    # (optional) move to a new line
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
        echo
        echo -e "\e[32m Creating platform \e[0m\t"
    else
        echo
        echo -e "\e[32m Not creating platform \e[0m\t"

    fi
}

if [ -n "$(type -t $FUNCTION_NAME)" ] && [ "$(type -t $FUNCTION_NAME)" =
function ];
then $FUNCTION_NAME $2; else help; fi

据我所知,我只需要让它可以执行
chmod +x cluster
在这之后,我应该为它创建一个系统链接ln -s cluster /bin/cluster
现在我应该可以在终端中输入cluster vc,它应该执行脚本,但是它一直给我“找不到命令集群”
我做了什么明显的错误吗?或者我需要用另一个chmod来运行它吗?

最佳答案

符号链接目标相对于符号链接位置进行解析。在您的例子中,这意味着如果您运行/bin/cluster,它将在cluster中查找名为/bin/directory(目标)的文件。提供指向文件的相对路径或链接到绝对路径:ln -s /path/to/cluster /bin/cluster
还要确保目标位置是可读的,并且可以由执行符号链接的人执行。

关于linux - 创建虚拟集群的Bash脚本不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44809988/

10-12 20:27