[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible Feature Requests (unsource, exchange)

From: Dave B
Subject: Re: Possible Feature Requests (unsource, exchange)
Date: Tue, 7 Jul 2009 19:46:01 +0100
User-agent: KMail/1.9.10

On Tuesday 07 July 2009, Christopher Roy Bratusek wrote:

> Hi all,
> what I'm currently missing are the following two things (I'm not 100%
> sure if they are not available):
> unsource: the opposite of source (while source is making functions
> publically available, unsource would remove them)

source does not make any function available. It just reads and executes the 
contents of the sourced file in the current context. If that file happens to 
contain functions, those functions will be defined and available (not to 
children though, unless they're exported), but it's just a side effect. 
To "remove" a function, you just unset it:

$ foo() { echo "function foo"; }
$ foo
function foo
$ unset foo
$ foo
bash: foo: command not found

> exchange: exchanges the value of two variables (x=2 y=a; exchange x y;
> x=a y=2 -- need to be exported, so $1 $2 inside a function/script don't
> help that much)

The traditional way to exchange values between two variable is to use a 
temporary variable:

$ x=a
$ y=2
$ tmp=$x
$ x=$y
$ y=$tmp
$ echo "now x is $x, y is $y"
now x is 2, y is a

It's not clear to me what you mean by "$1 $2 inside a function/script don't 

> echo no-expand: if you do echo $@ ($@ is $x $y for example) echo will
> print the values of $x $y instead of simply $x and $y is there a way to
> achieve this?

Sure, just quote it (and not only here, btw):

$ foo() { echo "$@"; }
$ foo '$x' '$y'
$x $y


reply via email to

[Prev in Thread] Current Thread [Next in Thread]