如何将以下
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