0

Here is some pseudo-code for what I'm trying to achieve with a bash program.

This program will be called with either:

filesplit -u OR filesplit --update

filesplit

 if -u (or --update) is set:

   echo "Update"

 else:

   echo "No Update

How can this split be achieved in a bash script?

1

3 Answers 3

2

Just use logical or || in a [[ ... ]] condition:

if [[ $1 == -u || $1 == --update ]] ; then
    echo Update
else
    echo No Update
fi
Sign up to request clarification or add additional context in comments.

Comments

2

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

1 Comment

extglob is only needed for using extended patterns when doing filename generation. Extended patterns are assumed inside [[...]].
1
case "$1" in
  -u|--update)
      echo update
      ;;
  *)
      echo no update
      ;;
esac

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.