skip to Main Content

I want to get the string arm64 in a bash script.

root@ubuntu-arm-test:# uname -a

Linux ubuntu-arm-test 5.15.0-105-generic #115-Ubuntu SMP Mon Apr 15 09:52:04 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux

I could do something like this:

#!/bin/bash

# Get the machine hardware name
arch=$(uname -m)

# Convert aarch64 to arm64
if [ "$arch" == "aarch64" ]; then
    echo "arm64"
else
    echo "$arch"
fi

But I would like to have a simpler way.

2

Answers


  1. Chosen as BEST ANSWER

    On Debian systems you can use:

    dpkg --print-architecture
    

  2. You can do this in one line using sed:

    arch=$(uname -m | sed 's/^aarch64$/arm64/')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search