I am using a program that takes a "command" as an argument and then adds some helpful wraping around it. Presumably in an effort to be helpful it appears to checks to make sure the command "exists". As far as I can tell this check is something like which. In my bash shell commands like set and export are built in and therefore which doesn't return anything.

Is there a way to set an environment variable without using a shell builtin.

My thought was to do something like define set.sh to be

#! /bin/bash
export $1

but this seems mildly crazy


No. Only the shell can change its own environment; set and export must always be built-ins.

This is also true of cd, alias and so on.

The best I can suggest is to reimplement your wrapper using a shell function. Either that or a shell script that you "source". Either way, a wrapper that runs inside the shell can do these things more seemlessly.


A possible workaround for your original problem would be a wrapper for your wrapper (Xzibit image not included):


temp=$(mktemp -d)

> "$temp/$command"
chmod a+x "$temp/$command"



rm -r "$temp"

This creates an empty executable which will pass your wrapper's tests without overriding the command that you actually want to run (the builtin).

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.