English 中文(简体)
B. 在地方篮子功能变量中设定一个字母的环境变量
原标题:Setting environment variables for a script in a local bash function variable

我有“灯塔”功能,可操作一种与习俗环境变量相平的文字。 我想避免出口现金中的相关变量,而只是把这些变量作为执行指挥的一部分放在文字上。

If I set the variables directly in the command -- e.g., VARNAME=VARVAL script_name -- it works well. However, since I want to set multiple variables, based on different conditions, I want to use a local function variable to store the environment variable settings, and then use this variable in the script execution command. I have a local "vars" variable that is ultimately set, e.g., to VARNAME=VAR, but if I try to run ${vars} script_name from my bash function, I get a "command not found" error for the $vars variable assignment -- i.e., the content of $vars is interpreted as a command instead of as environment variables assignment.

I tried different variations of the command syntax, but so far to no avail. Currently I have to export the relevant variables in the function, before calling the script, and then unset/reset them to the previous values, but this is not really the solution I was hoping for.

任何帮助都将受到高度赞赏。

Thanks, Sharon

最佳回答

将贵变量的内容作为表达而不是指挥加以评价。

eval ${vars} script_Name
问题回答

However, since I want to set multiple variables, based on different conditions, I want to use a local function variable to store the environment variable settings, and then use this variable in the script execution command.

你们不需要将变量储存在一个单独的变量中。 你们可以为指挥分配一个以上变量:

$ cat test.sh 
#!/usr/bin/env bash
echo "$foo"
echo "$bar"
$ foo=abc bar=def ./test.sh 
abc
def

http://mywiki.woolant.org/BashFAQ/048“rel=“nofollow”>afer,eval





相关问题
cygwin file path tab completion not working

How can I set up Cygwin to have tab completion? Actually, I do have it automatically, but it does not seem to complete paths. How do I set it up to complete paths?

cygwin version of idle has erroneous I/O handling

I am using idle (python 2.5) via cygwin on a windows vista machine and when I try to open an already existing .py file I see the full file path /home/aaron/C:/cygwin/home/aaron/script.py on the ...

Trying to get a terminal to work in Emacs

I ve been having a lot of problems with emacs and trying to get the terminal to work with: M-x term I installed cygwin and I fixed up my .emacs to include the paths: (setenv "PATH" (concat "...

Piping Cygwin into a Python program

As a i m new to the whole Piping thing and Python I had recently encountered a problem trying to pipe Cygwin s stdin & stdout into a python program usin Python s subprocess moudle. for example I ...

Unable to chdir() on Git/Cygwin

I installed Git via Cygwin on Windows Server. It works out very well. However there s a small issue that when I clone a repo use the command as following: $git clone git@myserver:project.git I ...

Linux Development C/C++/bash/python on windows-7

Before resorting to stackoverflow, i have spend a lot of times looking for the solutions. I have been a linux-user/developer for few years, now shifting to windows-7. I am looking for seting-up a ...

Cygwin/Git/Gitosis unable to push new repository

I ve recently set up cygwin, git, and gitosis on my Windows Server 2003 box and am having troubles. I ve followed just about every tutorial I can find to the letter, and have confirmed that my git ...

热门标签