Visit Our UNIX and Linux User Community


How to run a new shell with copy of current shell declarations?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to run a new shell with copy of current shell declarations?
# 1  
Old 03-10-2008
How to run a new shell with copy of current shell declarations?

How to run another shell and have all current shell dectaration copied to that new shell?

I would like to have available all current declarations in a new shell. That are functions, aliases, variables.

I need to test some functions that use the 'exit', but running it in current shell on 'exit' will close the shell, which I do not like.
# 2  
Old 03-10-2008
Code:
# export thing=hello
# echo $thing
hello
# bash
# echo $thing
hello
#

I don't see the problem...
# 3  
Old 03-10-2008
I had a similar issue recently and found that I could use the "return" command and it wouldn't kill my session.
ex:
return 10

This is under ksh.
# 4  
Old 03-11-2008
The problem is:
The only EXPORTED variables are copyed.
I need many functions and declared not exported variables.
I am running functions which change and define variables.
Some of them need to be run in separate process, in '()': like >(funct_boo)
I do not want redeclare all functions, aliases and variables in the new process

Code:
src> alias boo="echo boo-boo"
src> foo()
> {
> echo "foo from func";
> }
src> foo
foo from func
src> boo
boo-boo
src> var=variable
src> echo $var
variable
src> hm
dca0701> bash
executing file .bashrc - starting the bash shell--
----> Start of the .myset file  <---
----> End   of the .myset file  <---
src> foo
bash: foo: command not found
src> boo
bash: boo: command not found
src> echo $var

src>

The return() I have used, but it is not cover my situation.
There is a stack of functions, if somewhere something has not-0-return I need to stop execution of all stacked function, but do not kill the shell.
Return works only for one function.

Is any other possibility exist?
# 5  
Old 03-27-2008
Still have no idea how to do it.
Is it possible to run another shell and have all FUNCTIONS and ALIASES from current shell be available in new one?
# 6  
Old 03-27-2008
bash has an -a option to automatically export all variables and functions, dunno if this is a bashism but I would guess it's POSIX. Try "set -a" at the top of the script.

In bash, it seems you can't export aliases. All the more reason to use functions instead of aliases.
# 7  
Old 05-30-2008
Quote:
Originally Posted by era
bash has an -a option to automatically export all variables and functions, dunno if this is a bashism but I would guess it's POSIX. Try "set -a" at the top of the script.

In bash, it seems you can't export aliases. All the more reason to use functions instead of aliases.
Thank you, ERA, for advise, but I could not have it work.
Not sure where 'set -a' should be used:
- in original shell, where function and variables are defined and where new shell is started
- whith start shell command, like : >bash -a
- in new shell after starting

I have tried all 3 way but do not have any success.
Code:
--193:/home/dca0701/develop/src> alias boo="echo boo-boo"
--193:/home/dca0701/develop/src> foo()
> { echo "foo from func";  }
--195:/home/dca0701/develop/src> var=variable
--195:/home/dca0701/develop/src> ec $var; boo; foo
variable
boo-boo
foo from func


--196:/home/dca0701/develop/src> bash -a
executing file .bashrc - starting the bash shell--

----> Start of the .myset file  <---
----> End   of the .myset file  <---
--193:/home/dca0701/develop/src> ec $var; boo; foo

bash: boo: command not found
bash: foo: command not found
--193:/home/dca0701/develop/src> exit


--197:/home/dca0701/develop/src> set -a
--198:/home/dca0701/develop/src> bash
executing file .bashrc - starting the bash shell--

----> Start of the .myset file  <---
----> End   of the .myset file  <---
--193:/home/dca0701/develop/src> ec $var; boo; foo

bash: boo: command not found
bash: foo: command not found
--193:/home/dca0701/develop/src> exit


--199:/home/dca0701/develop/src>
--199:/home/dca0701/develop/src>
--202:/home/dca0701/develop/src> bash
executing file .bashrc - starting the bash shell--

----> Start of the .myset file  <---
----> End   of the .myset file  <---
--194:/home/dca0701/develop/src> set -a
--195:/home/dca0701/develop/src> ec $var; boo; foo

bash: boo: command not found
bash: foo: command not found
--196:/home/dca0701/develop/src>


Previous Thread | Next Thread
Test Your Knowledge in Computers #319
Difficulty: Medium
The open source program Redis is a relational database server.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Converting shell to Perl I run into shell built in function trap and need alternative in Perl

I am working on converting shell to Perl script. In shell we have built in function trap Do you know alternative in Perl or actually we don't need it? Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies

3. Shell Programming and Scripting

Current shell session hungs when run another binary

Hi, I am on AIX 7.1 and when I try to login to my account and sudo to other generic account (mqm user) my ssh session just hungs. ================== $ id uid=16150(sxp) gid=179(rax) groups=1179(raxs) $ $ $ sudo su - mqm Password: -------- Changed username to: mqm -------- .... (1 Reply)
Discussion started by: bdpl
1 Replies

4. UNIX Desktop Questions & Answers

command to run another shell on top of your default shell?

Can someone point me to the right command to to run another shell on top of your default shell? Thanks PS If admin sees this It is not home work. I am old man who wants to learn unix in my spare time. I CURRENTLY DO NOT GO SCHOOL, COLLEGE OR UNIVERSITY. (2 Replies)
Discussion started by: Bill Thompson
2 Replies

5. Shell Programming and Scripting

[How To?] Run shell script and get output into another shell.

Hi guys, I have a simple question, I want to store the output of the following command: As you can see it is running all the time, and we get a new line every 3sec. I just want to store these new lines into a single variable, so I can use it into a script. To clear the screen, and... (4 Replies)
Discussion started by: Thireus
4 Replies

6. Shell Programming and Scripting

How to run cmds after changing to a new env (shell) in a shell script

Hi, I am using HP-UNIX. I have a requirement as below I have to change env twice like: cadenv <env> cadenv <env> ccm start -d /dbpath ccm tar -xvf *.tar ccm rcv .... mv *.tar BACKUP but after I do the first cadenv <env> , I am unable to execute any of the later commands . ... (6 Replies)
Discussion started by: charlei
6 Replies

7. Shell Programming and Scripting

Help need to make a shell script run for ffmpeg vhook watermaking in shell

i have a small problem getting a batxh shell script to run in shell this is the code the problem seems to be centered around the ffmpeg command, something maybe to do with the ' ' wrapping around the vhook part command this is a strange problem , if i take the ffmpeg command and... (1 Reply)
Discussion started by: wingchun22
1 Replies

8. Shell Programming and Scripting

Run a C Shell using only Bash shell

Hi, I have only bash on my system. And I want to run a C shell... Is there a way for that? (3 Replies)
Discussion started by: HSN
3 Replies

9. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies

10. UNIX for Dummies Questions & Answers

How to run a command in shell 'A' from shell 'B'

Hello all.. I just want to login(ssh) to another system and run 'poweroff' command. This must be accomplished via a shell script($sh Myhalt host_name) and not from my bash!! Any idea??? :rolleyes: (1 Reply)
Discussion started by: rakabarp
1 Replies

Featured Tech Videos