我试图通过使用 if/then/else 语句在脚本中调用一个函数,但是当我运行它时我一直没有得到任何输出。例如:
start()
{
if [ -z /etc/redhat-release ]
then mta
else cron
fi
}
mta()
{
exim -bpc
}
cron()
{
crontab -l
}
这可以在 BASH 中实现吗?
最佳答案
注意:
- 在调用它的函数之前声明函数,这是一个好习惯;
cron
是 Unix/Linux 系统中的常用命令,请为您的功能使用其他名称。#!/bin/bash mta() { # your code here } mycron() { # your code here } start() { if [ -z /etc/redhat-release ]; then mta else mycron fi } start
关于linux - 使用 If/Then/Else 语句在 BASH 脚本中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29895454/