Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-17-2009, 10:03 AM   #1
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
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,079

Rep: Reputation: 401Reputation: 401Reputation: 401Reputation: 401Reputation: 401
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

cd /
Then source it:

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

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.


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:24 PM.

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