0

I have a utility bash script from an old laptop that I'm trying to use on my current laptop. It fails because it's passing unknown options to the column command. Running man column, I see that this machine is using the BSD version of the command; the script is written for the Linux version, which has more options.

I don't have access to the old machine, so I can't say much about what might have been done to set it up, except that it should be very similar to the new one. The current machine is running Pop!OS 20.04, newly installed in the last couple days.

Is there an obviously correct way to specify which of these similar commands I want to use?

1
  • This turns out to be a deeply frustrating problem. The relationships between the different repo/distro managers are snarled; they know they're shipping the wrong version of the command, but nobody's taking bets on when the issue will get fixed (this is hardly a mainstream problem, and nobody want's to break anything that's currently working). This ubuntu question has working solutions for my current problem, and links for people who want to dig into the underlying problem. Jun 16 at 18:52
2

Is there an obviously correct way to specify which of these similar commands I want to use?

At the risk of being a little too obvious, one obvious way is to specify the full path to the exact executable you want the script to use:

#!/usr/bin/env bash

# use the col executable in /usr/bin, not that other one:
col='/usr/bin/col'

$col ... ... ...

As @muru points out, an alternative would be to declare a function col() which calls the specific binary that you wish to use:

#!/usr/bin/env bash

# use the col executable in /usr/bin, not that other one:
col()
{
  /usr/bin/col "$@"
}

col ... ... ...
0
0

Find them all with, e.g. type -a column, rearrange your $PATH so that the directory containing the version you want is before the directory containing the version you don't want. Then, issue the rehash command.

PATH editing is tricky. Never have a PATH= assignment that doesn't have $PATH in it, unless you're really sure what you're doing.

I use Stephen Collyer's bash_path_funcs, described in Linux Journal way back in 2000:

https://www.linuxjournal.com/article/3645 https://www.linuxjournal.com/article/3768 https://www.linuxjournal.com/article/3935

The addpath function adds an entry to a path only if it is not there in the first place. delpath -n deletes all non-existent directories from a path.

You can get the pathfunc.tgz file from https://web.archive.org/web/20061210054813/http://www.netspinner.co.uk:80/Downloads/pathfunc.tgz

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.