LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-19-2007, 07:36 AM   #1
elmu
LQ Newbie
 
Registered: Feb 2005
Posts: 17

Rep: Reputation: 0
Include source problem with sh


Hello,

I have problems with including shell script inside an other script. I have 2 files - see below - where I try to use a varible in file 1 which was defined in file 2. It works fine with ksh but now I have to write it in bourn shell and it doesn't work.

Any idea?

File 1: (test.sh)
Code:
#!/bin/sh
echo "Test started source the other file"
./intern.sh
echo "Test is ${TEST}"
File 2: (intern.sh)
Code:
#!/bin/sh
TEST=/tmp
export TEST
 
Old 06-19-2007, 07:52 AM   #2
trashbird1240
Member
 
Registered: Sep 2006
Location: Durham, NC
Distribution: Slackware, Ubuntu (yes, both)
Posts: 463

Rep: Reputation: 31
Hi,

My main experience is with zsh; it looks like your included script is executed inside a new shell, in which case the variables will not carry over. You may be able to pass them as arguments to the new shell.

HTH

Joel
 
Old 06-19-2007, 07:52 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
You need to source the intern.sh script, not execute it in a subshell as you did.
Code:
. ./intern.sh
 
Old 06-19-2007, 11:56 AM   #4
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Or this:

source ./intern.sh
 
Old 06-19-2007, 02:05 PM   #5
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
Quote:
Originally Posted by gnashley
Or this:

source ./intern.sh

There is no source command in most shells; it is limited to csh (which is not recommended for scripting) and bash.

The standard command to source a script (i.e., execute it in the current shell) is dot, e.g.:

Code:
. /path/to/script
 
Old 06-20-2007, 08:53 AM   #6
trashbird1240
Member
 
Registered: Sep 2006
Location: Durham, NC
Distribution: Slackware, Ubuntu (yes, both)
Posts: 463

Rep: Reputation: 31
Lightbulb

Quote:
Originally Posted by cfaj
[INDENT]
There is no source command in most shells; it is limited to csh (which is not recommended for scripting) and bash.
The cool thing about the Z Shell is that it is most shells. And it does include a "source" command If Z Shell is unavailable, I understand; if you have the means, I highly recommend picking it up.

Joel
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ include file problem pwrlftr220 Programming 4 08-06-2006 10:26 PM
does mandrake linux official 10.1 include source code along with it? guy24x Mandriva 2 01-26-2005 11:05 AM
#include <windows.h> problem blufire Programming 5 11-26-2004 03:58 AM
gcc on 9.1 include problem skywarp Slackware 3 06-04-2004 10:05 PM
How to rebuild rpm database to include source installs abrb220 Linux - Software 3 03-18-2004 09:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration