== A Unix shell trick This is the sort of trick where I present the code first and explain it afterwards: > _arch=`(PATH=$HOME/bin:/local/bin:$PATH arch || echo unknown) 2>/dev/null`_ (This has been slightly modified to keep the line length down; in the real version, more things are added to _$PATH_. Note that this may be word-wrapped in your browser.) This sets the _$arch_ variable to the output of the _arch_ command, if there is one to be found in any number of places, and otherwise gives _$arch_ the value of 'unknown', all in one line. It's worth unpacking this into its component parts (somewhat abbreviated) in order to see how it works: - _PATH=$HOME/bin:/local/bin:$PATH arch_: Search for an _arch_ command using a temporarily augmented and altered _$PATH_. - _... || echo unknown_: If we failed to find an _arch_, supply a default value; a command that isn't found is a false condition, just as if the command itself failed. (We assume that _arch_ itself will never fail.) - _(...) 2>/dev/null_: Discard any complaint from the shell about being unable to find _arch_. (Using just '_$PATH=... arch 2>/dev/null_' wouldn't suppress the '_arch: not found_' error message, because the error message comes from the shell, not from a theoretical _arch_. We have to use a subshell in order to be able to redirect the shell's own error message.) This is the kind of thing that makes programming in the Bourne shell [[fun and interesting ../programming/BourneListMatch]], and I say that non-sarcastically. === Sidebar: why I do this Why I do this requires slightly more explanation. I have a single generic _.profile_ that I use on all of the systems I have accounts on, and on some of them my home directory is shared across multiple architectures, which means that I need to add an architecture-specific directory to my _$PATH_ (for architecture dependent binaries), which means that I need to know what the local architecture is. (By local tradition, 'architecture' here includes the operating system as well as the chipset; typical values are things like 'solaris-sparc'.) There is a vague local tradition that there is an _arch_ command that prints out a string suitable for this. However, not all systems follow this tradition, and not all systems put _arch_ in the same place, and sometimes I need to fake it with a _$HOME/bin/arch_ (if, for example, I am in a multi-architecture environment that doesn't follow this tradition). So determining the local architecture requires dealing with all of these possibilities, hence the one-liner.