Es posible la detección de 32 bits vs 64 bits en un script de bash?[duplicar]

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

  •  01-07-2019
  •  | 
  •  

Pregunta

Esta pregunta ya tiene una respuesta aquí:

Estoy escribiendo un script de bash para lidiar con algunas de las instalaciones de forma automatizada...Tengo la posibilidad de conseguir uno de esos programas en 32 o 64 bits en binario...es posible detectar la arquitectura de la máquina de bash para que yo pueda seleccionar el binario correcto?

Esto será para máquinas Ubuntu.

¿Fue útil?

Solución

¿

uname -a

darle cualquier cosa que usted puede usar?No tengo una máquina de 64 bits para hacer pruebas.


Nota de Mike Stone: Esto funciona, aunque específicamente

uname -m

Le dará "x86_64" para 64 bits, y algo más, para otros 32 bits tipos (en mi 32 bits VM, es "i686").

Otros consejos

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

getconf LONG_BIT parece hacer el truco así, lo que hace aún más fácil de comprobar esto ya que este simplemente devuelve el entero en lugar de complicadas expresión.

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

Tenga cuidado, en un chrooted 32 bits env, el comando uname sigue respondiendo como el de 64 bits de host del sistema.

getconf LONG_BIT funciona bien.

file /bin/cp o cualquier conocido ejecutable o una biblioteca debe hacer el truco si usted no tiene getconf (pero usted puede almacenar los programas que no uso, y tal vez no hay en este lugar).

Usted puede usar , en la siguiente secuencia de comandos (i extracto de esto desde oficialmente guión de "ioquake3") :por ejemplo

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

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

Estoy haciendo un script para detectar la "Arquitectura", este es mi código simple (la estoy usando con el vino , para mi los Juegos de Windows , en Linux , por cada juego , yo uso diverso de la versión de WineHQ, descargado de "PlayOnLinux" del sitio.

# 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

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

Ahora puedo usar esto en mi scripts de bash , porque funciona mejor en cualquier distro .

# 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


Recuerde, hay otras arquitecturas de CPU de Intel/AMD...

Se podría hacer algo como esto:

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

Sí, uname-a debe hacer el truco.ver: http://www.stata.com/support/faqs/win/64bit.html.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top