I have a BASH script that allows a user to specify a jobname. Right now we except everything. We feed this jobname into another executable that can only accept the following formats:

job_name, jobname, job-name, job_name1, job-name1, jobname1, job_name[1-5] job-name[1-5] or jobname[1-5] or other permutations that are alphanumeric (case sensitive) and [, ], _, -

I'm looking for way to trap the name and reject anything that doesn't follow that format. Started trying to use the regex with if statement but the [] seem to be throwing me for a loop.

if [[ $1 =~ [']_-['] ]]; then
   echo "I have the Square Braces"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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