Skip to main content
added 21 characters in body
Source Link
anubhava
  • 790.1k
  • 67
  • 603
  • 671

UsingYou can check for both values using extglob@(val1|val2) you can do thissyntax inside [[...]]:

shopt -s extglob
filesplit() {
    [[ "${1?needs an argument}" == -@(u|-update) ]] && echo "Update" || echo "No Update"
}

Testing:

filesplit -b
No Update
filesplit -u
Update
filesplit --update
Update
filesplit --update1
No Update
filesplit
-bash: 1: needs an argument

Using extglob you can do this:

shopt -s extglob
filesplit() {
    [[ "${1?needs an argument}" == -@(u|-update) ]] && echo "Update" || echo "No Update"
}

Testing:

filesplit -b
No Update
filesplit -u
Update
filesplit --update
Update
filesplit --update1
No Update
filesplit
-bash: 1: needs an argument

You can check for both values using @(val1|val2) syntax inside [[...]]:

filesplit() {
    [[ "${1?needs an argument}" == -@(u|-update) ]] && echo "Update" || echo "No Update"
}

Testing:

filesplit -b
No Update
filesplit -u
Update
filesplit --update
Update
filesplit --update1
No Update
filesplit
-bash: 1: needs an argument
Source Link
anubhava
  • 790.1k
  • 67
  • 603
  • 671

Using extglob you can do this:

shopt -s extglob
filesplit() {
    [[ "${1?needs an argument}" == -@(u|-update) ]] && echo "Update" || echo "No Update"
}

Testing:

filesplit -b
No Update
filesplit -u
Update
filesplit --update
Update
filesplit --update1
No Update
filesplit
-bash: 1: needs an argument