Tagged Questions
36
votes
2answers
3k views
$VAR vs ${VAR} and to quote or not to quote
I can write
VAR=$VAR1
VAR=${VAR1}
VAR="$VAR1"
VAR="${VAR1}"
the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
14
votes
4answers
805 views
keep duplicates out of $PATH on source
I have the following code that's source-d by my .shellrc
PATH="${PATH}:${HOME}/perl5/bin"
PATH="${PATH}:${HOME}/.bin"
export PATH
but if I make changes to other code and then source this file, my ...
6
votes
3answers
10k views
How to set global environment variables at boot through a script, and have them available for an application that runs before login?
I have a service that runs at boot, and in that service it calls a bash script in the background that exports some environment variables. The problem I'm having is that those environment variables ...
5
votes
2answers
4k views
Set Variable Environment Variables in bash (or other)
I want my script to read a file containing key/value pairs of environment variables to set, and then to set them.
So far, I have this:
#!/bin/bash
cat $1 | while read kv
do
key=${kv%=*}
...
5
votes
2answers
567 views
Local variables in zsh: what is the equivalent of bash's “export -n” in zsh
I'm trying to contain the scope of a variable to a shell, and not have children see it, in zsh. For example, I type this in .zshrc:
GREP_OPTIONS=--color=always
But if I run a shell script with the ...
5
votes
1answer
67 views
What else can break if I remove export from a variable?
My problem is that when I started coding my script I encountered several variable scope issues which resulted in the bad habit of exporting almost all my variables.
Now that my code has got quite ...
4
votes
7answers
899 views
how to share environment variables between shells like globals related to a master pid?
So, I need to share environment variables between shells, and that the changes on the variables be promptly recognized by all shells, like global variables. But they must be related to a master pid, ...
4
votes
2answers
133 views
Expansion of a shell variable and effect of glob and split on it
This post actually contains two separate questions but I think grouping them together will give some more context. I have gone through this question on quotes around variables but I do not quite ...
4
votes
1answer
141 views
how to set environment variables from a shell script? [duplicate]
I'm trying to set environment variable through a shell script. Here is the script with various techniques:
#!/bin/sh
echo "export SOMEPATH=/root/some" >> /root/.bash_profile
echo "export ...
3
votes
1answer
92 views
Difference between “.” and “./” while setting the environment variables using export? [duplicate]
Please excuse me if I am not clear while asking questions. I will try my best to be very clear while asking questions.
While learning Embedded Linux, we are setting an environment for our project. ...
3
votes
2answers
1k views
sourcing a file inside a script
I'd like to source a file inside a tcsh script. In code:
#!/bin/tcsh
unsetenv LD_LIBRARY_PATH
source $1
echo $LD_LIBRARY_PATH > temp_file
The expected result: The environment variable set ...
2
votes
1answer
119 views
Bash script for running python virtual environment does not execute
I am trying to wrap the following call into a script, which runs my Python virtual environment:
[lucas@lucas-ThinkPad-W520]/home/lucas/bin$ source ...
2
votes
1answer
2k views
Users home path in a bash script
I'm writing a bash-script that will be run as a cron job everyday. Very basic, I was wanting to change the wallpaper daily. I have mint-14 with mate.
The thing I'm getting caught up on right now ...
2
votes
1answer
2k views
How can I set environment variable permanently through shell script?
Let's say I have a script:
#!/bin/bash
echo $1
if [[ ! $1 ]];then
echo "True"
fi
export ABC="/home/aashish"
ABC is not available after the execution of this script. How can I make that variable ...
2
votes
2answers
1k views
Sharing Variables across sub shell scripts
I have a Main shell that runs a profile, The profile contains some variables such as Count. When I call the main shell, it loads the profile and then call another shell script. I want that inner shell ...
1
vote
2answers
559 views
Checking if PATH contains $HOME/mydir and adding it if not (all in a script) [duplicate]
Possible Duplicate:
keep duplicates out of $PATH on source
I am not an expert with Unix scripting. Some of my scripts are located in $HOME/mydir. Unfortunately, they are not accessible from ...
1
vote
3answers
441 views
Accessing bash [internal] brace expansion iteration number/variable
Question:
Is it possible to access which number of a bash iteration is currently being processed?
Psuedo-Command
mv {1..5}.something.{1..5} $x1.$x2.something
Note: This is a logical ...
1
vote
1answer
1k views
How to assign result of sed to variable
Below is a complete copy of a demo I'm using to to figure out to get the sed command to get rid of the spaces in a persons name, and compress it down to not have spaces.
Once this is done, I want to ...
1
vote
1answer
230 views
Environment auto-install script
When I work, I often have to switch computers or virtual machines which means that every time I switch, I have to set up my (Linux) environment again.
Is there a tool (in contrast to a simple bash ...
1
vote
1answer
23 views
Sourcing scripts with a for loop for different variables
I have several shell scripts that I summarised within a global script. I am using some variables that are the same across all scripts, and I wrote a separate script for this, which I am sourcing in ...
0
votes
1answer
367 views
Shell script executing in the terminal but not from shell script file [duplicate]
Possible Duplicate:
How can I make variables “exported” in a bash script stick around?
I have a problem with executing script from file. When I type in command line
...
0
votes
1answer
368 views
difficalty to save traceroute output in shell variable?
I need to filter and store traceroute output in shell variable (array). But I am getting some unusual output.
As I try to explain in following lines.
My present directory is temp, having some ...
0
votes
1answer
87 views
Colon breaks the variable subsitution [closed]
I am trying to lookup some C functions so that I could debug while using strace. So I setup a bash function to look it up in firefox (or links), but the substitution falls apart with : and escaping ...
-1
votes
3answers
1k views
How to run a shell script with export command in crontab
I have a shell script that exports values of variables when executed. The same values will be used in another script.
How to run this script(test.sh) in cron.
#!/bin/sh
export I="10"
echo $I
I will ...
-3
votes
1answer
80 views
where is this HOME environment variable and what do I have to add -H too it?
I recently attempted to run a boot up script which failed I didn't know why it failed so I posted a question about that here.
chkconfig bootup script failing, script runs good manually
Where the ...