ksh
export name="bhargav"
csh setenv name bhargav
Trying like this and from windows Iam using plink command to get the variable value. But it showing the error undefined variable
For the target-user, does Linux have bash or ksh as the shell for that user? If Linux is configured with bash as the shell, then ensure that the ~/.bashrc exports that variable. If Linux is configured with ksh as the shell for the user account (instead of bash), try exporting the variable in ~/.profile
Related
I have a bash script where I am trying to use values of some environment variables. Those variables are defined - I see the keys and values if I run printenv.
Also, these variables are defined and exported like
export FOO="bar"
in both ~/.bash_profile and ~/.bashrc.
I am trying to execute the script via ./script-name which fails to get the environment variables. If I run sudo -E ./script-name, that somehow gets the script the variables it needs.
Confused as to why these variables aren't available to the script even when they are exported in above files.
The only thing I can think of, is that for some reason, the shell process which you are calling to run the script, does not have full read access to your current environment.
ls -al /usr/bin/bash
ls -al /bin/sh
Assuming neither of them are symlinks, make sure that your current user has read and execute priveleges. A safer (in security terms) option, would be for you to install bash in ~/opt, and use #!~/opt/bin/bash as your shebang line.
I've searched for an answer and read about different ways to do that in Mac but some of them are not relevant for Mojave or just didn't work for me.
I need to set Environment variable in terminal (bash), run script that creates processes, and I would like those processes to know the value of those environment variables.
How can I do that?
btw - writing export ENV_NAME=ENV_VAL in .bashrc or in .bash_profile didn't work.
Works for me. Have you RTFM? For example, ~/.bashrc is only read by interactive shells, not shell scripts. And ~/.bash_profile is only read by login shells. Again, shell scripts don't usually use the -l flag that would make them login shells. Also, if you put an export VAR=value statement in your ~/.bashrc it won't affect your current interactive shell. You need to start a new shell; e.g., by typing exec bash. Once you do that you should find the env var is defined. And it will be inherited by any process, including a shell script, you launch from that interactive session.
Note that if you run your script via crontab, for example, then you'll need a different means of setting the env var. For example, by using the --init-file flag or the BASH_ENV env var.
I'm having an issue with an AIX 5.3 machine, the default shell is ksh and it behaves well, but I want to use bash in order to have bash completions and some syntax advantages it offers but whenever I type bash, when I want to run any command, when I hit Enter key it only makes a line break and my command is never executed, like if it is expecting a multiline text.
Here there are some file scripts in my home dir:
.profile
USER=`whoami`
export HOST USER
export PS1='$USER#$HOST:$PWD=> '
ENV="$HOME/.kshrc"
export ENV
export EXINIT='set nu ai sm'
.kshrc
set-o vi
alias dir='ls -ltr'
Example:
=> pwd
/
=> bash
$ pwd
What is wrong with my configuration that produces this behaviour?
I have a shell script that exports a couple of environment variables that are needed for building a software project (Android Keystore Location).
Usually when I call the script the environment variables are exported, and the IDE can access them, so does the export command on the Bash Terminal.
Since I installed Mac OS X El Capitan, the environment variable set by the Bash command
export FOO="bar"
are not returned when I try to access them by
echo $FOO
on the shell. Instead I only get a empty line returned.
If I use printenv from within the shell script $F00 is displayed.
When I call printenv from the Cash terminal $FOO is missing.
I read that the OS X "El Capitan" updates fixes some security issues concerning bash. Could that be the cause ?
You cannot modify or export variables in the shell with a shebang script (a script whose first line begins with #! and the pathname of an executable), if that's what you're doing, because that creates a separate process to execute the script and any variables it exports are only visible to its child processes.
You can only arrange for a script to modify variables in the current shell by executing the script within the current process with . (or source) for example.
For example, the ~/.bashrc, ~/.bash_profile and ~/.bash_logout scripts are executed directly by the shell, so they can set or export variables to be inherited by commands and sub-shells run from the shell.
I am having a similar issue. It seems that environment variables are not being propagated to child processes from bash. I solved it by explicitly adding the variables I need to the child.
export MYVAR=foo
MYVAR=$MYVAR ./executable_to_launch
I would be interested to see if someone has found a better solution.
I have the following script in ~/bin/ in order to override the default command for gnome-terminal:
#!/usr/bin/env bash
XDG_CONFIG_HOME=~/.config/darkthemesettings /usr/bin/gnome-terminal
I am trying to make the XDG_CONFIG_HOME variable only get seen by gnome-terminal, but in terminal that appears, if I run any other program, the variable is also set in that program. Running echo $XDG_CONFIG_HOME from the terminal gives
/home//.config/darkthemesettings
I understood that if one sets an environment variable without using export, that variable is only available in the script that sets it, not in any child processes. Am I incorrect? How can I achieve what I want here? Thanks
You can use env to unset the variable for the command run inside the terminal, like this:
XDG_CONFIG_HOME=~/.config/darkthemesettings gnome-terminal -x env -u XDG_CONFIG_HOME bash
The assignment XDG_CONFIG_HOME=~/.config/darkthemesettings before the command gnome-terminal sets the variable for the terminal. The terminal will run the arguments after the -x option as shell command. That shell command bash is prefixed by env -u XDG_CONFIG_HOME which unsets the variable in the environment for running bash.
Your understanding is incorrect. Without export they are bash variables. export "promotes" them to environment variables.
You will need to have gnome-terminal run a script that unsets the variables before running the shell.