Hot answers tagged

8

Many pointed out that MY_VAR="$toto" will assign to MY_VAR the current value of $toto or an empty string in case $toto is unset (or in case $toto itself contains an empty string obviously), but I'm surprised no one pointed out yet that MY_VAR="$toto" will not set an environment variable but rather a shell variable (unless a variable named MY_VAR is already ...


7

Your example does not illustrate your question. $ toto="somevalue" $ MY_VAR="$toto" $ echo $MY_VAR somevalue $ To do what you asked, you'd need: MY_VAR='$toto' or MY_VAR="\$toto" Can't tell for sure if it's bad practice. Personally I don't see any obvious problem.


3

sed and arithmetic do not mix. The right tool for jobs like this is awk. Consider this test file: $ cat test.txt /nonmatching/line 1 /home/username/Pictures/properties/wallpaper/span/tree.jpg 2 /another/non/matching/line 5 We can increment the number of the line that you want with: $ line="/home/username/Pictures/properties/wallpaper/span/tree.jpg" $ ...


2

To answer your exact question: Yes, it is bad practice to have a dollar sign in the value of an environment variable. However, that's not what the code snippet you have displayed actually does. MY_VAR="$toto" $ is a special character to your shell (whether bash or dash), and unless protected against variable expansion, you won't actually be putting a ...


2

For the specific case of /etc/environment, no, a $ in the variable value doesn't mean anything special. /etc/environment is a file read by a PAM module named pam_env, and pam_env has specific syntax for interpreting $: In /etc/environment, it is left uninterpreted. In /etc/security/pam_env.conf and ~/.pam_environment (a user-specific file), pam_env treats ...


1

You can go two different ways: Using single quotes: break out of the single quotes and reference the variable (using double quotes to prevent word splitting and filename expansion): sudo sed -i 's/$sUrl . $this_sOutDir/https:\/\/'"$bucketname"'.s3.amazonaws.com . $this->_sOutDir/g' /var/www/html/$name/core/oxconfig.php Using double quotes: escape the ...


1

You want export myEnv not export $myEnv


1

In addition to what Gunnar already noted, export will make the variable available only to that instance of bash shell and its child processes. In addition tcsh and bash syntax differ when it comes to variables. I would suggest you set a variable in the syntax familiar to tcsh eagle:~/sergrep> cat var_file.txt setenv foo "TEST" eagle:~/sergrep> ...


1

When you call source ~/.bashrc you reload your ~/.bashrc configuration only for that current terminal session. You have to do it for all other existing terminal sessions as well if you want to reload your ~/.bashrc


1

The system-wide zprofile (/etc/zsh/zprofile) in Ubuntu contains: # /etc/zsh/zprofile: system-wide .zprofile file for zsh(1). # # This file is sourced only for login shells (i.e. shells # invoked with "-" as the first character of argv[0], and # shells invoked with the -l flag.) # # Global Order: zshenv, zprofile, zshrc, zlogin emulate sh -c 'source ...


1

Official documentation says ...sudo has a default policy of resetting the Environment and setting a secure path (this behavior is defined in /etc/sudoers). And ...you can setup sudo not to reset certain environment variables by adding some explicit environment settings to keep in /etc/sudoers. Just do this user@here:$ sudo su root@here:$ ...


1

First, have a look at this answer to understand the differences between login and non-login shells. Basically, they read different initialization files. Now, many distributions—including Debian and, by extension, Ubuntu—are actually moving towards what you describe. On these distributions, the default ~/.profile or ~/.bash_profile files contain something ...



Only top voted, non community-wiki answers of a minimum length are eligible