È possibile rilevare 32 bit contro 64 bit in uno script bash? [duplicare]

StackOverflow https://stackoverflow.com/questions/106387

  •  01-07-2019
  •  | 
  •  

Domanda

    

Questa domanda ha già una risposta qui:

         

Sto scrivendo uno script bash per gestire alcune installazioni in modo automatizzato ... Ho la possibilità di ottenere uno di questi programmi in binario a 32 o 64 bit ... è possibile rilevare l'architettura della macchina da bash quindi Posso selezionare il binario corretto?

Questo sarà per le macchine Ubuntu.

È stato utile?

Soluzione

non

uname -a

ti dà tutto ciò che puoi usare? Non ho una macchina a 64 bit su cui testare.


Nota di Mike Stone: funziona, sebbene specificamente

uname -m

Fornirà " x86_64 " per 64 bit e qualcos'altro per altri tipi di 32 bit (nella mia macchina virtuale a 32 bit, è " i686 ").

Altri suggerimenti

MACHINE_TYPE=`uname -m`
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
  # 64-bit stuff here
else
  # 32-bit stuff here
fi

getconf LONG_BIT sembra fare anche il trucco, il che rende ancora più facile verificarlo poiché restituisce semplicemente il numero intero anziché un'espressione complicata.

if [ `getconf LONG_BIT` = "64" ]
then
    echo "I'm 64-bit"
else
    echo "I'm 32-bit"
fi

Fai attenzione, in un chroot ed env a 32 bit, l'Uname sta ancora rispondendo come il sistema host a 64 bit.

getconf LONG_BIT funziona bene.

file / bin / cp o qualsiasi eseguibile o libreria noti dovrebbero fare il trucco se non hai getconf (ma puoi memorizzare programmi che non puoi usare, e forse ci sono non in questo posto).

Puoi usare il seguente script (estraggo questo dallo script ufficiale di " ioquake3 "): ad esempio

archs=`uname -m`
case "$archs" in
    i?86) archs=i386 ;;
    x86_64) archs="x86_64 i386" ;;
    ppc64) archs="ppc64 ppc" ;;
esac

for arch in $archs; do
    test -x ./ioquake3.$arch || continue
    exec ./ioquake3.$arch "$@"
done

=============================================== ===================================

Sto realizzando uno script per rilevare " Architecture " ;, questo è il mio semplice codice (lo sto usando con wine, per i miei giochi Windows, sotto Linux, per ogni gioco, utilizzo una versione diversa di WineHQ, scaricata dal sito "PlayOnLinux".

# First Obtain "kernel" name
KERNEL=$(uname -s)

if      [ $KERNEL = "Darwin" ]; then
        KERNEL=mac
elif        [ $Nucleo = "Linux" ]; then
        KERNEL=linux
elif        [ $Nucleo = "FreeBSD" ]; then
        KERNEL=linux
else
        echo "Unsupported OS"
fi

# Second get the right Arquitecture
ARCH=$(uname -m)

if         [ $ARCH = "i386" ]; then
            PATH="$PWD/wine/$KERNEL/x86/bin:$PATH"
            export WINESERVER="$PWD/wine/$KERNEL/x86/bin/wineserver"
            export WINELOADER="$PWD/wine/$KERNEL/x86/bin/wine"
            export WINEPREFIX="$PWD/wine/data"
            export WINEDEBUG=-all:$WINEDEBUG
            ARCH="32 Bits"
    elif    [ $ARCH = "i486" ]; then
            PATH="$PWD/wine/$KERNEL/x86/bin:$PATH"
            export WINESERVER="$PWD/wine/$KERNEL/x86/bin/wineserver"
            export WINELOADER="$PWD/wine/$KERNEL/x86/bin/wine"
            export WINEPREFIX="$PWD/wine/data"
            export WINEDEBUG=-all:$WINEDEBUG
            ARCH="32 Bits"
    elif    [ $ARCH = "i586" ]; then
            PATH="$PWD/wine/$KERNEL/x86/bin:$PATH"
            export WINESERVER="$PWD/wine/$KERNEL/x86/bin/wineserver"
            export WINELOADER="$PWD/wine/$Nucleo/x86/bin/wine"
            export WINEPREFIX="$PWD/wine/data"
            export WINEDEBUG=-all:$WINEDEBUG
            ARCH="32 Bits"
    elif    [ $ARCH = "i686" ]; then
            PATH="$PWD/wine/$KERNEL/x86/bin:$PATH"
            export WINESERVER="$PWD/wine/$KERNEL/x86/bin/wineserver"
            export WINELOADER="$PWD/wine/$KERNEL/x86/bin/wine"
            export WINEPREFIX="$PWD/wine/data"
            export WINEDEBUG=-all:$WINEDEBUG
            ARCH="32 Bits"
         elif [ $ARCH = "x86_64" ]; then
            export WINESERVER="$PWD/wine/$KERNEL/x86_64/bin/wineserver"
            export WINELOADER="$PWD/wine/$KERNEL/x86_64/bin/wine"
            export WINEPREFIX="$PWD/wine/data"
            export WINEDEBUG=-all:$WINEDEBUG
            ARCH="64 Bits"
    else
        echo "Unsoportted Architecture"
fi

=============================================== ===================================

Ora lo uso nei miei script bash, perché funziona meglio in qualsiasi distribuzione.

# Get the Kernel Name
Kernel=$(uname -s)
case "$Kernel" in
    Linux)  Kernel="linux"              ;;
    Darwin) Kernel="mac"                ;;
    FreeBSD)    Kernel="freebsd"            ;;
* ) echo "Your Operating System -> ITS NOT SUPPORTED"   ;;
esac

echo
echo "Operating System Kernel : $Kernel"
echo
# Get the machine Architecture
Architecture=$(uname -m)
case "$Architecture" in
    x86)    Architecture="x86"                  ;;
    ia64)   Architecture="ia64"                 ;;
    i?86)   Architecture="x86"                  ;;
    amd64)  Architecture="amd64"                    ;;
    x86_64) Architecture="x86_64"                   ;;
    sparc64)    Architecture="sparc64"                  ;;
* ) echo    "Your Architecture '$Architecture' -> ITS NOT SUPPORTED."   ;;
esac

echo
echo "Operating System Architecture : $Architecture"
echo
slot8(msd):/opt # uname -a
Linux slot8a 2.6.21_mvlcge500-electra #1 SMP PREEMPT Wed Jun 18 16:29:33 \
EDT 2008 ppc64 GNU/Linux


Ricorda, esistono altre architetture di CPU diverse da Intel / AMD ...

Potresti fare qualcosa del genere:

if $(uname -a | grep 'x86_64'); then
  echo "I'm 64-bit"
else
  echo "I'm 32-bit"
fi

Sì, uname -a dovrebbe fare il trucco. vedi: http://www.stata.com/support/faqs/win/ 64bit.html .

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top