Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 21 May 2013, 03:28
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
A Bash programming question [solved]
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [7 Posts]  
Author Message
scsijon

Joined: 23 May 2007
Posts: 923
Location: the australian mallee

PostPosted: 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
View user's profile Send private message Visit poster's website 
dawg

Joined: 09 Aug 2009
Posts: 106
Location: still here

PostPosted: Wed 11 Apr 2012, 09:06    Post subject:  

I'm guessing you're also new to programming in general. Smile 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! Smile

_________________
I used to only like Puppy as a friend, but now I think our relationship is starting to develop into something more... Very Happy
Back to top
View user's profile Send private message 
ICQ Number 
chromoite


Joined: 02 Apr 2012
Posts: 40

PostPosted: Wed 11 Apr 2012, 16:55    Post subject:  

Learn BASH scripting
_________________
Outer Limits Fan Smile Puppy Linux Forum
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 833

PostPosted: 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
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 3843

PostPosted: 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
View user's profile Send private message 
Moose On The Loose


Joined: 24 Feb 2011
Posts: 278

PostPosted: 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
View user's profile Send private message 
scsijon

Joined: 23 May 2007
Posts: 923
Location: the australian mallee

PostPosted: 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
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [7 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0489s ][ Queries: 12 (0.0034s) ][ GZIP on ]