| Author |
Message |
scsijon
Joined: 23 May 2007 Posts: 923 Location: the australian mallee
|
Posted: Wed 11 Apr 2012, 02:21 Post subject:
A Bash programming question [solved] |
|
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: |
#!/bin/bash
MAGEIA_VERSION= 1||2||c
|
that doesn't look right?
Can I have some guidance please![/code]
_________________ Mage2 in final Beta! http://www.murga-linux.com/puppy/viewtopic.php?t=72565
Last edited by scsijon on Sat 14 Apr 2012, 20:52; edited 1 time in total
|
|
Back to top
|
|
 |
dawg
Joined: 09 Aug 2009 Posts: 106 Location: still here
|
Posted: Wed 11 Apr 2012, 09:06 Post subject:
|
|
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... 
|
|
Back to top
|
|
 |
chromoite

Joined: 02 Apr 2012 Posts: 40
|
Posted: Wed 11 Apr 2012, 16:55 Post subject:
|
|
Learn BASH scripting
_________________ Outer Limits Fan Puppy Linux Forum
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 833
|
Posted: Wed 11 Apr 2012, 17:16 Post subject:
|
|
scsijon,
Several possibilities - here's two....
| Code: | 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
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Thu 12 Apr 2012, 01:42 Post subject:
|
|
| Code: | 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: | case "$MAGEIAVERSION" in
1|2|c)the_function;;
*)echo "$MAGEIAVERSION" not supported && exit;;
esac |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
Moose On The Loose

Joined: 24 Feb 2011 Posts: 278
|
Posted: Thu 12 Apr 2012, 21:25 Post subject:
|
|
| technosaurus wrote: | | Code: | 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: | case "$MAGEIAVERSION" in
1|2|c)the_function;;
*)echo "$MAGEIAVERSION" not supported && exit;;
esac |
|
how about
| Code: |
1|2|c)v${MAGEIAVERSION}_function;;
|
|
|
Back to top
|
|
 |
scsijon
Joined: 23 May 2007 Posts: 923 Location: the australian mallee
|
Posted: Fri 13 Apr 2012, 22:32 Post subject:
|
|
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
_________________ Mage2 in final Beta! http://www.murga-linux.com/puppy/viewtopic.php?t=72565
|
|
Back to top
|
|
 |
|