Article 5J5PQ [SOLVED] Bash: Is there a more elegant way to write if statement

[SOLVED] Bash: Is there a more elegant way to write if statement

by
GPGAgent
from LinuxQuestions.org on (#5J5PQ)
My bash script takes 3,5,7,9 or 11 arguments, a file name and a start and stop point to cut from the file, up to five start and stop points, so this is what I've constructed, is there a more elegant way:Code:#!/bin/bash
renice 19 -p $$
if [[ $# -eq 3 ]] || [[ $# -eq 5 ]] || [[ $# -eq 7 ]] || [[ $# -eq 9 ]] || [[ $# -eq 11 ]] ; then
:
else
echo "====================================================================="
echo "Please enter the Input file name start point and duration in hh:mm:ss"
echo "Example: abc.mts 12:00 15:00 i.e. starts at 12 min and ends at 15 min"
echo "You can have up to 5 cuts from a single file"
echo "====================================================================="
exit 1
fi

echo "No of parameters: $#"
echo "Processing file $1"
echo "start at $2"
echo "end at $3"

exit 0Okay there is no actual processing code, I just want to get the framework of the script done. It works like this,

No Parameters:Code:jonke@charlie:~$ HB-Cutter.sh
11316 (process ID) old priority 0, new priority 19
=====================================================================
Please enter the Input file name start point and duration in hh:mm:ss
Example: abc.mts 12:00 15:00 i.e. starts at 12 min and ends at 15 min
You can have up to 5 cuts from a single file.
=====================================================================
jonke@charlie:~$Three arguments:Code:jonke@charlie:~$ HB-Cutter.sh abc.mp4 12:24 15:30
11321 (process ID) old priority 0, new priority 19
No of parameters: 3
Processing file abc.mp4
start at 12:24
end at 15:30
jonke@charlie:~$Four arguments:Code:jonke@charlie:~$ HB-Cutter.sh abc.mp4 12:24 15:30 18:20
11335 (process ID) old priority 0, new priority 19
=====================================================================
Please enter the Input file name start point and duration in hh:mm:ss
Example: abc.mts 12:00 15:00 i.e. starts at 12 min and ends at 15 min
You can have up to 5 cuts from a single file
=====================================================================
jonke@charlie:~$Five arguments:Code:jonke@charlie:~$ HB-Cutter.sh abc.mp4 12:24 15:30 18:20 20:36
12065 (process ID) old priority 0, new priority 19
No of parameters: 5
Processing file abc.mp4
start at 12:24
end at 15:30
jonke@charlie:~$and yes, I've not printed the 4th and 5th argument, but when finished the script will process themlatest?d=yIl2AUoC8zA latest?i=CW-xyCwEWa4:-JHWXxspOBk:F7zBnMy latest?i=CW-xyCwEWa4:-JHWXxspOBk:V_sGLiP latest?d=qj6IDK7rITs latest?i=CW-xyCwEWa4:-JHWXxspOBk:gIN9vFwCW-xyCwEWa4
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments