[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bash scripting



Jeff Elkins wrote:
> ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e 
> s/arm.*/arm/ -e s/sa110/arm/
> 
> I'm working on polishing my meagre shell scripting skills and would
> appreciate some feedback on the line above, quoted from the kernel Makefile.

Ew, that line seems to be so specific.  You might want to check out
config.guess from the gnu archive or any gnu program that uses it.  It
is a *VERY* long script to more completely do the above.  In general,
avoid needing the architecture like that.  But sometimes you can't
avoid it.

> 1. How would you use this in a straight bash script so it returned a value
> containing the boxes architecture?

  uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/

But really just uname -m is fine.

  case "$(uname -m)" in
    i?86) echo Hello x86, pleased to meet you. ;;
    ia64) echo Hello ia64, pleased to meet you. ;;
  esac

But there are lots of machine variants.  Trying to enumerate them all
is a path of frustration.

> 2. As far as comparisons go, if I wanted to determine if a string contained
> ".xyz" or ".abc" would that be a variant of the fragment above?

Contained?  Or ending in?  Contained:

  string="dog.xyz"
  case "$string" in
    *.xyz*) echo Hello .xyz, pleased to meet you. ;;
    *.abc*) echo Hello .abc, pleased to meet you. ;;
  esac

Ending in:

  string="dog.xyz"
  case "$string" in
    *.xyz) echo Hello .xyz, pleased to meet you. ;;
    *.abc) echo Hello .abc, pleased to meet you. ;;
  esac

Bob

Attachment: pgpXnwoXetxew.pgp
Description: PGP signature


Reply to: