Re: Comparing strings

Lewis <[email protected]> Tue, 13 Jul 2021 21:00:29 -0000 (UTC)
Newsgroups alt.comp.lang.shell.unix.bourne-bash
Organization Miskatonic U
Message-ID <[email protected]>
In message <[email protected]> Grant Taylor <[email protected]> wrote:
>> if [ "$1" != "FOO" ];

if [[ $1 != "FOO" ]];

work for me.

> I would be tempted to try a case statement:

> case ${1} in
> 	FOO)
> 		# FOO's specific backup.
> 	BAR|BOB)
> 		# specific backup for BAR and BOB.
> 	*)
> 		# default backup for all other systems.
> esac

Case is what I would do as well.

> I also find that such a case statement is a lot easier to maintain long 
> term as systems are added / changed / removed.

And that's why

> Depending on how the backups work, you might consider breaking out the 
> actual backup actions to their discrete steps and call them as a 
> function.  E.g. FOO would call functions 1 and 2, while BAR & BOB call 
> functions 2 and 3, and then everyone else would only call functions 1 
> and 3.  Use the case as a method to choosoe which pieces to run and then 
> call the necessary common pieces.

Agreed.

-- 
The more you tighten your grip, Tarkin, the more star systems will
	slip through your fingers.