A Bash programming question [solved]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
scsijon
Posts: 1596
Joined: Thu 24 May 2007, 03:59
Location: the australian mallee
Contact:

A Bash programming question [solved]

#1 Post by scsijon »

Beginner, don't yell please! I have looked at and downloaded a number of the bash tutorials and have a lot of unanswered questions still.

I'm trying to sort out Barry's mageia2ppm to handle a number of possibilities for a field in the one list as it's changed in mageia2 where files in the file lists can now have an inclusion of:
mga1, still used mageia 1 files,
mga2, new mageia2 compiled files,
or mgac, the talked about Mageia 'cauldron' file directory, which is their "here be dragons" level files. Currently mageia 2 beta lives there!

Task Problem No1.

I want to setup the following

Variable MAGEIA_VERSION = '1' or '2' or 'c' (the digits 1, 2, or the lowercase letter c) only.

so it should look like?

Code: Select all

#!/bin/bash

MAGEIA_VERSION= 1||2||c 

that doesn't look right?

Can I have some guidance please![/code]
Last edited by scsijon on Sun 15 Apr 2012, 00:52, edited 1 time in total.

dawg
Posts: 116
Joined: Sun 09 Aug 2009, 14:36
Location: still here
Contact:

#2 Post by dawg »

I'm guessing you're also new to programming in general. :) And I don't think Bash is a good "first" programming language, but since you're at it, you may want to look into arrays.

Anyway, I'm not a Bash expert, I'm sure others will be able to offer more efficient help in learning how to do what you wanna do with it. I wish you all the best on your journey! :)
I used to only like Puppy as a friend, but now I think our relationship is starting to develop into something more... :D

User avatar
chromoite
Posts: 22
Joined: Mon 02 Apr 2012, 10:40

#3 Post by chromoite »

Outer Limits Fan :) [url=http://www.puppylinuxforum,org]Puppy Linux Forum[/url]

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#4 Post by seaside »

scsijon,

Several possibilities - here's two....

Code: Select all

if grep -Eq  '1|2|c'  <<<$MAGEIA_VERSION; then echo ok; fi

And-

 case $MAGEIA_VERSION  in   -1|2|c) echo ok  ;;  esac

Cheers,
s

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#5 Post by technosaurus »

Code: Select all

case "$MAGEIAVERSION" in
  1)v1_function;;
  2)v2_function;;
  c)vc_function;;
  *)echo "$MAGEIAVERSION" not supported && exit;;
esac
or if they are all use the same function you can simply

Code: Select all

case "$MAGEIAVERSION" in
  1|2|c)the_function;;
  *)echo "$MAGEIAVERSION" not supported && exit;;
esac
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

#6 Post by Moose On The Loose »

technosaurus wrote:

Code: Select all

case "$MAGEIAVERSION" in
  1)v1_function;;
  2)v2_function;;
  c)vc_function;;
  *)echo "$MAGEIAVERSION" not supported && exit;;
esac
or if they are all use the same function you can simply

Code: Select all

case "$MAGEIAVERSION" in
  1|2|c)the_function;;
  *)echo "$MAGEIAVERSION" not supported && exit;;
esac
how about

Code: Select all

  1|2|c)v${MAGEIAVERSION}_function;;

scsijon
Posts: 1596
Joined: Thu 24 May 2007, 03:59
Location: the australian mallee
Contact:

#7 Post by scsijon »

no, dawg, just little use for a decade or two down at this level! Use to do everything by scripting back in the '70's and 80's. Brain doesn't get used with information, information gets lost or overwritten!

Perfecto technosaurus, that first bit of code should deal with two problems at once, thanks. I'm trying to sort out the mageia2ppm file converter problem (t=75739 and t=56867) as it will become a major problem soon as mageia2 is due out as release on 14th May. I'm using it for qtpuppy!

thanks to all

Post Reply