ruby – 如何计算和检查传递的参数?

前端之家收集整理的这篇文章主要介绍了ruby – 如何计算和检查传递的参数?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何将以下 Ruby代码翻译为Bash?
if ARGV.length == 0
    abort "\nError: The project name is required. Aborting...\n\n"
elsif ARGV.length > 2
    abort "\nError: The program takes two arguments maximum. Aborting...\n\n"
end

解决方法

#!/bin/bash
USAGE="$0: <project name> [subproject attribute]"
if [ $# -lt 1 ]; then echo -e "Error: The project name is required.\n$USAGE" >&2; exit 1; fi
if [ $# -gt 2 ]; then echo -e "Error: Two arguments maximum.\n$USAGE" >&2; exit 1; fi
原文链接:https://www.f2er.com/ruby/265360.html

猜你在找的Ruby相关文章