Can I export vars without polluting my namespace?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can I export vars without polluting my namespace?
# 1  
Old 06-06-2006
Can I export vars without polluting my namespace?

When I've got a long or hard to type file name, the following is something I like to do for convenience.
Code:
$export a=someReallyLongFileName; touch $a; chown hartmann $a
$ls
.  ..  someReallyLongFileName
$echo $a
someReallyLongFileName

But then, as you see with the echo, I have polluted my environment name space when I don't need it any more. Of course, I could always

Code:
export a=

to unset a, but I'm wondering if there's some conceptually more elegant way to do this. Thanks!

***********************

UPDATE: Figured out at least one way to do this. Use parens.

Code:
$( export a=someReallyLongFileName; touch $a; chown hartmann $a )
$ls *
someReallyLongFileName
$echo $a

$

Please do chime in if there are others.
# 2  
Old 06-06-2006
If namespace pollution worries you, then your solution of using brackets is neat. The enclosed commands run in a subshell so the variables evaporate after the commands have executed - though it does mean that you can't use them again if you need to access the file later.

To cut down on the typing, you could also use your shell's filename completion mechanism or use copy/paste if you've got a capable terminal emulator.

cheers
# 3  
Old 06-06-2006
If using ksh or bash, perhaps use the unset built-in function....
Code:
$ export a=someReallyLongFileName
$ echo $a
someReallyLongFileName
$ unset a
$ echo $a

$

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read vars iteratively

Hello, I have a tab delimited list of 311 server & account names which I want to read those 2 variables and then connect to each server and get info on that particular job account. I've tried the following: while read server acct; do printf "********$server\t $acct***********\n" ... (3 Replies)
Discussion started by: mcbobolink
3 Replies

2. UNIX for Dummies Questions & Answers

Virtualization of Global Namespace in UNIX

Hi all, I have a small Question here in Unix File System.I am unable to get a proper answer in Internet. Hope someone can get back to me soon. A Unix file system can mount filesystem of several disk partitions to form a single global space. Suppose that you wish to virtualize this global... (1 Reply)
Discussion started by: Pavan Kumar
1 Replies

3. Shell Programming and Scripting

getting vars from external files

Hi I have an issue, I want to get variables from an external file. Variable file var1=test var2-test2 I want to get these vars from another shell script. Does any one know how? (5 Replies)
Discussion started by: digitalviking
5 Replies

4. Shell Programming and Scripting

Set/Export Env Vars from with Shell Script With Input Variable

I have a shell script I want to run that will set environment variables based on the value of an input variable submitted when the shell script is called. For example: $ mgenv.sh prod This would set environment variables for prod $ mgenv.sh test This would set environment variables... (1 Reply)
Discussion started by: brtaylor73
1 Replies

5. Shell Programming and Scripting

How to remove xml namespace from xml file using shell script?

I have an xml file: <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only. I tried using sed... (10 Replies)
Discussion started by: Gary1978
10 Replies

6. Shell Programming and Scripting

check a list of vars

I have about 20 different variables that I need to check for null values then replace with a specific string if they are null. I've been doing this via 20 different if then statements like this: if ; then WIND="UUU" fi Is there a more elegant way to do this? The vars aren't sequential in... (6 Replies)
Discussion started by: audiophile
6 Replies

7. Shell Programming and Scripting

NEW: need help with nawk using -v vars

I'm trying to pass nawk a shell variable to be used in a pattern match. I can't get this work. I'm calling nawk from a /bin/sh I want that when somebody enters Trunk Group in variable TGR so it goes into nawk variable TG. echo "Enter TRUNK GROUP:" read TGR cat... (20 Replies)
Discussion started by: wakhan
20 Replies

8. Shell Programming and Scripting

Passing Vars between scripts

Im running a script that runs scripts within it self and i need to pass vars made in the original script to scripts run within it and the only way i can think to do it is right the string to a file and read the file in the script (4 Replies)
Discussion started by: rcunn87
4 Replies

9. Shell Programming and Scripting

need help with nawk using -v vars

I'm trying to pass nawk a shell variable to be used in a pattern match. I can't get this work. I'm calling nawk from a /bin/sh echo " Input file: \c" read var1 echo " Input: \c" read var2 nawk -F"|" -v x=$1 ' BEGIN $15 ~ /^'$var2'/ {print $2}' var1 {apary=$15; bparty=$23; time=$4;... (3 Replies)
Discussion started by: amon
3 Replies
Login or Register to Ask a Question