New answers tagged

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" $ ...


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

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


0

Short of having to edit a config after launching the container, instead you can just define the missing environment variable when you run the debian based container -e TERM=xterm as in this example export DUMMY_SERVER_NAME=itswednesday docker run \ -d \ --name $DUMMY_SERVER_NAME \ -e TERM=xterm \ --expose=80 \ debian /bin/bash -c "while [[ ...


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

You want export myEnv not export $myEnv


0

Not sure if this is a good solution, I added the following line into the ~/.profile: export SSH_AUTH_SOCK=/run/user/1000/keyring/ssh My key is unlocked on login.


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 ...


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 ...


0

For a list of all standard variables in bash - even the ones that are not useful - until one day when you need them: Search for Shell Variables in man bash in the section PARAMETERS: LESS="+/The following variables are set by the shell" man bash


0

Yes, this did work, using export: PATH=/bin:/usr/bin:/sbin:/usr/sbin export GDAL_DATA=/mnt/gdal/gdal-data export LD_LIBRARY_PATH=/mnt/gdal NAME=tomcat7 DESC="Tomcat servlet engine" ....


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 ...


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 ...


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.


0

After editing JAVA_HOME in /etc/environment, you should do: source /etc/environment export JAVA_HOME If you only source the new value, that won't get exported to any subprocess run from your shell.


0

There's no need to use both head and tail. AWK can print the line that you tell it to quite easily $> awk -v LINE=5 'NR==LINE' /etc/passwd sync:x:4:65534:sync:/bin:/bin/sync You can turn that into a function in your bash script (remember to quote the full or partial path to ...


0

it seems this is a problem with deviceQuery. When I start nvidia-smi -l 1 --query --display=PERFORMANCE >> gpu_utillization.log and then start a cuda compiled sample app, particles The log shows something interesting. At 'rest', before particles is started, GPU0 is in performance state 2 and GPU1 is in performance state 8. After particles is ...


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 ...



Top 50 recent answers are included