Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a expect script which opens an xterm
I figured out I need to use "exec" in order to open the xterm
exec xterm -e '...here is an expect script also..'
While I see it is OK to use several command in my script but not in that xterm script.
And later on I found all current environment variables are not set in that xterm
Why? Used bash some much and never meet that problem before. How can I let the xterm inherit all environment variables?
Independently from expect there is a rule of thumb for UNIX/Linux:
If you want to transfer a variable from parent process to its child process,
you must export this variable in the parent process.
You can check, if a variable XYZ has been exported indeed, using command
env|grep XYZ
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I'm getting accustomed to Linux (very new to it) and I was wondering if there is anything I can do to customize the root#kali:-# part (i know this signifies where I am in my computer) but I would like to change the colors and the format it is displayed in!
Could anyone help me out?
It's called the "prompt" and it's controlled with the PS1 shell variable.
References:
Bash manual
POSIX sh Shell Variables
Bash Prompt HOWTO
ps1 tag on Stack Overflow
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
Running either of these commands seems to start an SSH agent process successfully:
eval `ssh-agent`
OR
exec ssh-agent bash
I'm partial to the first one, because the second exec replaces the shell. Obviously the second, uses eval which is frowned upon by some, but I don't see alternatives.
My questions are:
Does exec have any negative side effects when replacing the shell or indeed any side effects at all? Are my concerns about using exec warranted?
I don't have an issue using eval but, out of interest what alternative commands are there without scripts or functions (and without exec or eval) to start an ssh-agent process in one line?
This is a "safe" use of eval, at least to the extent that you trust ssh-agent to output nothing but simple, hard-coded assignments similar to
SSH_AUTH_SOCK=/var/folders/...; export SSH_AUTH_SOCK;
SSH_AGENT_PID=xxxxx; export SSH_AGENT_PID;
echo Agent pid xxxxx;
The output of ssh-agent is specifically designed to be passed to eval, and let's face it: if ssh-agent wanted to do harm, it could do so in a quieter fashion.
The downside to using exec is that the new shell that replaces the original shell may not be identical; the environment is inherited, but some shell settings not found in .bashrc may be different. However, if you put exec ssh-agent bash in your .bashrc (especially as the last line), there there isn't really any opportunity for your shell's configuration to diverge from whatever .bashrc did. (There is also the possibility that you have non-idempotent code in your .bashrc, meaning that executing it twice will result in different behavior than having only executed it once. But again, that's unlikely and easily auditable.)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I am looking to execute a alias on my terminal which will login to another shell and execute a command there.
For example,
sh = 'ssh admin#x.x.x.x'
shls = 'sh;ls' (also tried 'sh && ls')
In this scenario, when i give 'shls', i want to ssh to (pwd less entry enabled) x.x.x.x and then execute ls command over there. But the 'ls' part is not working.
I understand the shell changed and hence its no longer in parent shell's scope to trigger the ls, but just wondering if there is a way to push it to the logged in shell and execute there.
Infact, i wanted to use another alias which is avaiable in x.x.x.x in place of 'ls' but as a first step i want to atleast get this working.
Hope i could put it clearly, Thanks in advance for your help.
You can pass a command to ssh as an argument (after the various connection parameters):
alias shls='ssh admin#x.x.x.x ls'
BTW, I'd recommend against aliasing sh -- that's a commonly used command to run a shell script(*), and giving it a different meaning could cause confusion.
(* Though instead using the sh command, it's generally better to give the script a proper shebang line, and just enter its path.)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
How can we update a variable from one shell to another shell ?
Suppose , I am having 2 Putty sessions opened , I want to set a variable in the first SHELL and I need that variable to access from the 2nd SHELL .
Is is possible ?
You can save the variable to a script.
Then source the script in the 2nd session.
For example:
# session 1
hello=world
echo "hello=$hello" > /tmp/var.sh
# session 2
. /tmp/var.sh
echo $hello
As each process' environment is protected, there's no way to share environment variables. I would suggest using a file on a shared filesystem to store the variable you want and reading that file in whenever you'd need to know what the new value is.
It is usually not possible, because each shell (and each process) has its own environment. See execve(2).
However, you might want to switch to the fish shell. It gives you so called universal variables which might be shared between several instances of (i.e. processes running) the fish shell. This is implemented thru the fishd user daemon (with which every fish process communicates).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
After I have installed node, it works. I quit terminal and then I can't use node command in bash. Would anyone know why this is happening? Its rather infuriating. I think it may be something to do with the $PATH variable not being initialised in the right order or not at all.
I followed the 1st option https://gist.github.com/isaacs/579814
Thanks to #DavidWeldon and #Vinayak Mishra
Add export PATH=$HOME/local/bin:$PATH in ~/.bash_profile and source ~/.bash_profile or exit and open new terminal. Create ~/.bash_profile it isn't available already.
If there is a problem with the $PATH, you can check it with:
echo $PATH && source ~/.profile && echo $PATH
If there are difference, files are not being called in the right order. Take a look at this.