【问题标题】:Rebuild shell script to case将 shell 脚本重建为大小写
【发布时间】:2015-06-13 10:02:27
【问题描述】:

我想稍微重建一下我的脚本,让它对其他人更容易。 我认为使用案例和功能会更容易。

IP="192.168.123." #$1 is the last number for the ip-address

regExp="^[0-9]+[-,0-9]*$"

if [ "$#" -eq 0 ]; then    
echo "No numbers given "
exit 0                 
fi

if [ "$1" == "-h" ]; then
    echo "Give numbers to test"
    exit 0               
fi

我想做这样的事情:

 if [ "$#" -eq 0 ]; then    
    echo "No numbers given "
    # exit 0    --> do I have to write this?

case
-h ) echo "Give numbers to test";   

esac      

    fi

我必须写那个出口吗? 有什么事情可以让它变得更容易吗?

【问题讨论】:

  • 半离题但是,你考虑过python吗?
  • 我只用ubuntu 2个月,不懂python :(
  • 如果您是 Linux 新手,请继续学习 shell 脚本。你在正确的轨道上。

标签: linux shell ubuntu scripting


【解决方案1】:

如果您的所有语句都在 case 内,那么您不需要退出

case "$1" in
  '') echo No numbers given;;
  -h) echo Give numbers to test;;
  *) ...
esac

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    • 2017-06-11
    相关资源
    最近更新 更多