You've been tasked with writing a script that processes input arguments. How would you check if the number of arguments provided to the script is less than 3?

  • if [ "$#" -lt 3 ]
  • if [ "$#" -eq 3 ]
  • if [ "$#" -gt 3 ]
  • if [ "$#" -eq 0 ]
To check if the number of arguments provided to the script is less than 3, you would use if [ "$#" -lt 3 ]. This tests whether the number of script arguments, represented by $#, is less than 3. Option 2 checks if the number of arguments is exactly 3, and Option 3 checks if it's greater than 3. Option 4 checks if there are no arguments.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *