Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

My script is called: report_startDate

It has the following line:

$JRE_ROOT/bin/java -cp /home/me/report/config/:/home/me/report/jar/reporting-1.0-SNAPSHOT.jar  com.me.project.report.Main $1

$1 makes it possible to for me to run the script as: ./report_startDate 20140717.

But the script also runs without the date. I want to make it mandatory for whoever runs this script to supply the date.

What could I replace $1 with to make it mandatory to supply date?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Put this at the top:

if [ -z "$1" ]; then
    echo "Argument required."
    exit
fi 

-z tests the argument string to see if it is of zero length.

If it's not zero length, execution will continue.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.