LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-17-2009, 10:03 AM   #1
mrbutabara
Member
 
Registered: Jan 2007
Location: Stafford, VA
Distribution: Ubuntu
Posts: 32

Rep: Reputation: 15
import and export command


hi everyone. Im sort of a newbie to linux and i was wondering if its possible to use the import command in scripting to use commands such as cd in a shell script. i understand that you cannot use the cd command in a shell script because it will have no effect on the parent shell. thats why i was wondering if you can use an import command of some kind to do this? well thanks a lot and i hope you can help.
 
Old 02-17-2009, 10:21 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by mrbutabara View Post
hi everyone. Im sort of a newbie to linux and i was wondering if its possible to use the import command in scripting to use commands such as cd in a shell script.
You seem to already understand why it doesn't work the way you want. So I will spare you that explanation.

By the time you are inside the script a new shell has already been spawned, so it is already too late to prevent that. In other words: nothing that you put inside the script can prevent it from launching a new instance of the shell, hence what you ask for is impossible by design.

However, you can do so from outside by sourcing the script. If you use this line into a script called test.sh:

Code:
cd /
Then source it:

Code:
source test.sh
It will work as expected. There's a short hand for "source", a simple dot:

Code:
. test.sh
Another possibility is to put an alias or a function in your ~/.bashrc or ~/.bash_profile files (read the INVOCATION section of the bash man page to get a complete picture of the bash initialization files and about aliases and functions). The shell rc files are sourced every time you open a new shell, hence, all the aliases and functions you drop into them will be available in every new shell you open.

Last edited by i92guboj; 02-17-2009 at 10:23 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to export/import users/passwords ? dlugasx Linux - Server 3 02-02-2009 07:33 AM
Export-Import with pipe files asi Linux - Software 2 06-05-2007 12:25 PM
Import/Export Thunderbird filters xri Linux - Software 2 01-07-2007 09:31 PM
Accessing import and export symbols ? unclesam Linux - Newbie 2 01-11-2006 09:14 AM
Import sys ?bash: import: command not found joirnange Linux - Newbie 4 12-28-2004 11:33 PM


All times are GMT -5. The time now is 08:07 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration