我正在写一个bash脚本以自动方式处理一些安装...我有可能得到32或64位二进制的一个这样的程序...是否有可能从bash检测机器架构,所以我可以选择正确的二进制?
这将适用于Ubuntu机器.
MACHINE_TYPE=`uname -m` if [ ${MACHINE_TYPE} == 'x86_64' ]; then # 64-bit stuff here else # 32-bit stuff here fi
getconf LONG_BIT
似乎也可以做到这一点,这使得检查它更容易,因为它只返回整数而不是一些复杂的表达式.
if [ `getconf LONG_BIT` = "64" ] then echo "I'm 64-bit" else echo "I'm 32-bit" fi
是否
uname -a
给你任何你可以使用的东西?我没有要测试的64位机器.
迈克斯通的注意事项:这是有效的,但具体而言
uname -m
将64位提供"x86_64",其他32位类型提供其他功能(在我的32位VM中,它是"i686").
请注意,在chroot
32位环境中,uname仍然像64位主机系统一样回答.
getconf LONG_BIT
工作良好.
file /bin/cp
如果你没有getconf(或者你可以存储你不能使用的程序,也许没有在这个地方),任何知名的可执行文件或库应该可以解决问题.
您可以使用以下脚本(我从"ioquake3"的官方脚本中提取):例如
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
================================================== ================================
我正在编写一个脚本来检测"架构",这是我的简单代码(我使用它与葡萄酒,对于我的Windows游戏,在Linux下,每个游戏,我使用不同版本的WineHQ,从"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
================================================== ================================
现在我在我的bash脚本中使用它,因为在任何发行版中都能更好地工作.
# 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
请记住,还有其他CPU架构,而不是英特尔/ AMD ......