Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer

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).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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