Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write an If statement that checks to see that the user has run the script with a

ID: 3600142 • Letter: W

Question

write an If statement that checks to see that the user has run the script with at least one command line argument. If the user does not, the script should print a usage message and quit. the usage message should contain the name of the script and should indicate that an argument filename is required. be sure to import any modules you need to do this. write an If statement that checks to see that the user has run the script with at least one command line argument. If the user does not, the script should print a usage message and quit. the usage message should contain the name of the script and should indicate that an argument filename is required. be sure to import any modules you need to do this.

Explanation / Answer

Hi,
This is quite simple, all command line arguements are accessed as $1,$2 etc in bash scripts, so check if parameters have been passed we can use,
if [ $# -eq 0 ]
then
echo "0 arguments given"
fi
Here $# holds the number command line arguements passed to the script
Thumbs up if this was helpful, otherwise let me know in comments