USER_DEV=&quot;abcd&quot; ENV=&quot;DEV&quot;  Requirement: to print the actual value abcd by substituting 2 variables as below? echo $(USER_$ENV) should return abcd. I get error as below: USER_ENV: command not found  Please suggest.
121699
I am getting a "bad substitution" error while running this code. I want to print the values in h_1, h_2, h_3with a for loop.  #/!/bin/bash h_1=12 h_2=13 h_3=14 for ((i=1; i&lt;=2; i++))  do   echo "${h_$i}" done
51449
Is there an easy way to substitute/evaluate environment variables in a file? Like let's say I have a file config.xml that contains:  &lt;property&gt;     &lt;name&gt;instanceId&lt;/name&gt;     &lt;value&gt;$INSTANCE_ID&lt;/value&gt; &lt;/property&gt; &lt;property&gt;     &lt;name&gt;rootPath&lt;/name&gt;     &lt;value&gt;/services/$SERVICE_NAME&lt;/value&gt; &lt;/property&gt;   ...etc. I want to replace $INSTANCE_ID in the file with the value of the INSTANCE_ID environment variable, $SERVICE_NAME with the value of the SERVICE_NAME env var. I won't know a priori which environment vars are needed (or rather, I don't want to have to update the script if someone adds a new environment variable to the config file). Thanks!
63360
I'm running Ubuntu 11.04. I use the terminal to start a bash session, and I want to add an environment variable:  $r@hajt:~$ env THEVAR=/example   But it's not working. It shows all the variables with THEVAR being the last one, but another call to env does not show THEVAR anymore- env | grep THEVAR returns nothing.  Similarly, scripts with export (export THEVAR=/example) or other variable assignments (THEVAR=/example) don't add the environment variable.  I know I'm doing something wrong, I know it should be something simple, but I just can't find what.  UPDATE: The real meaning of my question was this one:   (Anyway I'll choose the most voted answer and leave the edited title -that wasn't what I was asking)  env runs a program in a modified environment, then dismisses all the changes.
93050
I set some environment variables in a terminal, and then run my script. How can I pull in the variables in the script? I need to know their values. Simply referring to them as $MY_VAR1 doesn't work; it is empty.
51835
Is there a way to assign a value to a variable, that value which we get in terminal by writing any command?  Example command: sensors  From that we get CPU temperature. How can I assign this value to a temp_cpu variable?
12024
What is the difference between find . and /home/user/* as an input to for command.? For example:  for var in $(find .) do echo "$var" done   or  for var in /home/user/* do echo "$var" done   In the first case for command breaks up the file with names containing spaces. While in the second case it does not. Why?
39077
In my Bash environment I use variables containing spaces, and I use these variables within command substitution. What is the correct way to quote my variables? And how should I do it if these are nested? DIRNAME=$(dirname &quot;$FILE&quot;)  or do I quote outside the substitution? DIRNAME=&quot;$(dirname $FILE)&quot;  or both? DIRNAME=&quot;$(dirname &quot;$FILE&quot;)&quot;  or do I use back-ticks? DIRNAME=`dirname &quot;$FILE&quot;`  What is the right way to do this? And how can I easily check if the quotes are set right?
1260
I am trying to print a simple value for $AR1_p1 but the variable $i is not evaluating. for i in 1 2 3 4 do     AR1_p1=22     AR1_p2=23     AR1_p3=24     AR1_p3=25     echo $AR1_p$i done   It's like concatenating dynamically. Any suggestions on how to fix this?.
42872
I am trying something like:  set pwd = abc&amp;123 echo password %pwd%   I get the result as...   '123' is not recognized as an internal or external command, operable program or batch file.  password abc   Is the system like this or is there an escape for such characters?
12917
I would like to use variable substitution on a particular string that I access via a command. For example, if I copy something into my clipboard, I can access it like this.  $ xclip -o -selection clipboard Here's a string I just copied.   If I assign it to a variable, then I can do variable substitution on it.  $ var=$(xclip -o -selection clipboard) $ echo $var Here's a string I just copied. $ echo ${var/copi/knott} Here's a string I just knotted.   However, is there a way to do variable substitution without assigning it to a variable? Conceptually, something like this.  $ echo ${$(xclip -o -selection clipboard)/copi/knott} bash: ${$(xclip -o -selection clipboard)/copi/knott}: bad substitution   This syntax fails, because var should be a variable name, not a string.
34176
If I run  export TEST=foo echo $TEST   It outputs foo.  If I run  TEST=foo echo $TEST   It does not. How can I get this functionality without using export or a script?
85039
I have a system PATH variable with the system level config. I use the user PATH variable to complement the PATH with user-specific config.  I would like to update the user PATH variable from command-line for example with setx.  But I don't know how to reference the existing user path in setx.  In the following command (setx without /M)  setx PATH c:\my-user-specifc-bin-path;%PATH%   the first PATH means user PATH but the second %PATH% will be substituted by the "full" (user + system) PATH.  So it means that the entire system path would be duplicated in the user PATH... what is definitively not what I want.  I would like to:   Affect only the user PATH environment variable Append/Prepend one or more path element to the existing value Do it from the command-line.
91295
Why doesn't echo $1 print $1 in this simple bash script?    #!/bin/bash # function.sh print_something () { echo $1 } print_something  $ ./function.sh 123  -&gt; why doesn't it print '123' as a result?
98349
I have a bunch of piped shell commands that give some env output. I want to set these as env variables for an additional command to add to the chain  Kevins-MBP:ops kevzettler$ eb printenv | tail -n +2 | sed "s/ //g" NODE_ENV=staging RDSPassword=changme RDSHost=sa1c7quehy7pes5.lolol.us-east-1.rds.amazonaws.com RDSUsername=derp
60654
The question is about special variables. Documentation says:     !!:$      designates the last argument of the preceding command. This may   be shortened to !$.        ($_, an underscore.) At shell startup, set to the absolute pathname used  to invoke the shell or shell script being executed as passed in the    environment or argument list. Subsequently, expands to the last argument to the previous command after expansion. Also set to the full pathname  used to invoke each command executed and placed in the environment    exported to that command.    There must be some difference I cannot catch, because:  $ echo "hello" &gt; /tmp/a.txt $ echo "!$" echo "/tmp/a.txt" /tmp/a.txt  $ echo "hello" &gt; /tmp/a.txt $ echo $_ hello   What is the difference?
39419
I run the following script: VAR=&quot;Test&quot; sh -c 'echo &quot;Hello $VAR&quot;'  But I get: # ./test.sh Hello  How can I send the variable VAR of my script to the shell created with sh -c '...'?
72754
Is this a correct way for passing an environment variable in sudo ?  sudo -u www-data -b env FOOBAR="foobar" /home/user/folder/daemon