LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 09: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, 09:21 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
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 09:23 AM.
 
  


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:43 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