export / import


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting export / import
# 1  
Old 03-08-2011
export / import

I have a calling script which consists of calls to other scripts via the sh command.

ie vi callscript.sh
Code:
 sh  smallscript1.sh
 extra unix commands
 sh  smallscript2.sh
 exit


In smallscript1, I prompt for a filename, which I handle via :-
Code:
read f1
export f1



I then need to use $f1 later on, because I need to pass it’s value into the following script to allow files created in it to be named with this value.

In smallscript2.sh I define :-
Code:
   mv  run5.txt   /home/dir1/$f1_5.prt


But if I do a ‘ls –la’ in /home/dir1, all I see is .prt on its own.

Do I need the equivalent of an IMPORT f1 somewhere ?

Last edited by vbe; 03-08-2011 at 10:37 AM.. Reason: code tags please
# 2  
Old 03-08-2011
Can you execute the first script in the current shell it self?

I mean:

Code:
. smallscript1.sh
extra unix commands
sh smallscript2.sh
exit

# 3  
Old 03-08-2011
export & import

Hi panyam
Yes I can execute the 1st one.
In the 'extra unix commands' I use the prompted value.
It is just making it available in the called script that I cannot get to work.
Thanks for your help..
# 4  
Old 03-08-2011
Further to panyam
Quote:
. smallscript1.sh
The way you call smallscript.sh is important.
The dot-space-scriptname causes smallscript.sh to execute within the environment of callscript.sh. Thus any environment variables exported by smallscript.sh are available to smallscript2.sh .

Just noticed: There is a bug in smallscript2.sh
Quote:
mv run5.txt /home/dir1/$f1_5.prt
An underscore is a valid character in a variable name. We need curly brackets to tell Shell where the variable name stops!
Code:
mv  run5.txt   /home/dir1/${f1}_5.prt


Last edited by methyl; 03-08-2011 at 11:20 AM.. Reason: Just noticed...
This User Gave Thanks to methyl For This Post:
# 5  
Old 03-08-2011
This is what I did

Code:
 
$ cat main.sh
. scr1.sh
echo "Main Script"
echo $f1
sh scr2.sh
 
$ cat scr1.sh
read f1
export f1
 
$ cat scr2.sh
touch $f1

$ ./rem.sh
test_file ## I am inputting this value
Main Script
test_file

$ ls -l test_file
-rw-rw-rw-   1 cust       users            0 Mar  8 21:01 test_file

This User Gave Thanks to panyam For This Post:
# 6  
Old 03-09-2011
export / import

Hi panyam & methyl
I changed the 'sh' to the '.' when calling smallscript1, and inserted '{' & '}' around f1 in smallscript2, and my procedure now works great.
Many thanks for your kind assistances.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Array - Export/Import in global environment variables.

Hello. During startup /etc/bash.bashrc.local generates some array ..... source /.../.../system_common_general_array_env_var ..... The file system_common_general_array_env_var contains : LEAP_VERSION='42.3' ARRAY_MAIN_REPO_LEAP=('zypper_local' 'openSUSE-Leap-'"$LEAP_VERSION"'-Non-Oss' ... (2 Replies)
Discussion started by: jcdole
2 Replies

2. Homework & Coursework Questions

DB2 Export and Import Oracle

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: is this enough to make the data perfect export into delimited file? there are some posted that i read, they... (9 Replies)
Discussion started by: Sonny_103024
9 Replies

3. Homework & Coursework Questions

DB2 Export and Import Oracle

Hi Guys, I Just wanted your opinion/ suggestion/ Help on my unix script about db2 export data with deli file and import into oracle. db2 connect to Tablename user id using psswrd db2 "EXPORT TO '/cardpro/brac/v5/dev/dat/AAAAA.DEL' OF DEL select * FROM AAAAA" db2 "EXPORT TO... (3 Replies)
Discussion started by: Sonny_103024
3 Replies

4. Solaris

Zpool import/export error

A backup/clone script of ours was recently ran. It normally only clones the rpool and renames in rpoolA. Something must've changed as it found another one of our pools that it shouldn't have. It exported that pool unbeknownst to us. Later on when a coworker realized the other pool was missing he... (2 Replies)
Discussion started by: beantownmp
2 Replies

5. UNIX for Dummies Questions & Answers

Import and export PGP/GnuPG keys

Hi, I need to export an existing PGP key and import it into GnuPG on a different machine. This is how I did the export: pgp -kx myuser _myuser_public pgp -kx myuser _myuser_private secring.skr (this is from the pgp installation directory that contains secring.skr). This produced two... (0 Replies)
Discussion started by: imchi
0 Replies

6. Shell Programming and Scripting

manipulate text for openldap import/export question.

Hey guys.. I am not sure if this is the right place to post this - but here goes. I need to manipulate an openldap export to match a different schema so that I can import into that system. Basically - its just text manipulation. I have gotten alot of it done just by using simple sed, but I am sorta... (0 Replies)
Discussion started by: i2ambler
0 Replies

7. Solaris

Export/import ZFS ACL's

I've been wondering about this one, is there any way to do the following with ZFS ACL's (i.e. "copy" the ACL over to another file)? getfacl /bla/dir1 | setfacl -f - /bla/dir2 I know about inheritence on dirs, it doesn't work in this scenario I'm working on. Just looking to copy the ACL's. ... (3 Replies)
Discussion started by: vimes
3 Replies

8. Filesystems, Disks and Memory

Local NFS import / re-export using automount?

Hi, Can I do the following: On SunOS 5.8 /etc/vfstab: remote-host:/Volumes/webdata - /export/home/webdata nfs - yes rw,vers=3,soft,intr,bg,timeo=600 In /etc/auto_direct: /home/science $HOST:/export/home/webdata/science /home/science-edu ... (2 Replies)
Discussion started by: bloyall
2 Replies

9. UNIX for Dummies Questions & Answers

import

Dear All, If while the databsae was shut down, an import command has been done. Will the import result will return 1? Best Regards, Omran (1 Reply)
Discussion started by: omran
1 Replies

10. Shell Programming and Scripting

import

i'm importing tables to oracle 7, but sometimes import give me warnings (not failures) how can i rollback the whole imported tables if warnings occured please advise thanx (2 Replies)
Discussion started by: omran
2 Replies
Login or Register to Ask a Question