You are not logged in.

#1 2009-05-16 02:58:15

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

[Solved] Script To Check Architecture

I want to add an if statement to one of my scripts to check the architecture of the computer but I cant seem to get the formatting of the if statement right. heres what I have so far:

arch=`uname -m`

if [[ "$arch" == 'x86_64']]
then
    echo "x86_64"
else
    echo "i686"
fi

Last edited by brando56894 (2009-05-16 05:21:56)

Offline

#2 2009-05-16 03:07:46

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: [Solved] Script To Check Architecture

Look in the kernel PKGBUILD, if I'm correct it should have such a check already.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#3 2009-05-16 03:09:37

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: [Solved] Script To Check Architecture

if  [ "$arch" == "x86_64" ]

Offline

#4 2009-05-16 03:10:09

Allan
Member
From: Brisbane, AU
Registered: 2007-06-09
Posts: 10,946
Website

Re: [Solved] Script To Check Architecture

arch=`uname -m`

if [ "$arch" == "x86_64" ]
then
    echo "x86_64"
else
    echo "i686"
fi

Note only one "[" and spaces after "[" and before "]" and the consistent use of quotes.

or in one line...

[ "$arch" == "x86_64" ] && echo "x86_64" || echo "i686"

Offline

#5 2009-05-16 03:11:48

Xyne
Moderator/TU
Registered: 2008-08-03
Posts: 6,534
Website

Re: [Solved] Script To Check Architecture

#!/bin/bash

arch=$(uname -m)

if [ "$arch" == 'x86_64' ]
then
    echo "x86_64"
else
    echo "i686"
fi

This works for me.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#6 2009-05-16 03:17:49

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Re: [Solved] Script To Check Architecture

sweet thanks guys

Last edited by brando56894 (2009-05-16 05:21:42)

Offline

#7 2009-05-16 11:21:04

Arm-the-Homeless
Member
Registered: 2008-12-22
Posts: 273

Re: [Solved] Script To Check Architecture

Couldn't you do:

echo $(uname -m)

?

Offline

#8 2009-05-16 11:22:57

Allan
Member
From: Brisbane, AU
Registered: 2007-06-09
Posts: 10,946
Website

Re: [Solved] Script To Check Architecture

I'm guessing he wants to do something more complicated than the "echo" at some stage...

Offline

#9 2009-05-17 02:00:51

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Re: [Solved] Script To Check Architecture

You are correct. What I posted was just a simple statement test. I'm actually using it in my stage 2 installation script to select the proper pacman source files depending on whether its a 32 bit or 64 bit system.

Offline

#10 2009-05-29 07:20:52

Themaister
Member
From: Trondheim, Norway
Registered: 2008-07-21
Posts: 652
Website

Re: [Solved] Script To Check Architecture

Pretty nice smile This could be useful for one of my PKGBUILDs. (No, $CARCH doesn't work when in a chroot in my case tongue)

Last edited by Themaister (2009-05-29 07:24:02)

Offline

Board footer

Powered by FluxBB