LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-27-2009, 12:28 PM   #1
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Rep: Reputation: 40
stupid bash question, how to CD and stay in the new dir?


Hi group,

This is another case of "I should know this", but I can;t remember/

How do I write a bash script that will CD to a directory and stay there when the script ends?

I have tried:
. cd xxzzy
source cd xxzzy
bash -e cd xxzzy
I always get 'cd: No such file or directory' and it does exist.

If I make the command an alias, it works fine.

Any ideas??
 
Old 05-27-2009, 01:01 PM   #2
zens
LQ Newbie
 
Registered: Dec 2007
Posts: 4

Rep: Reputation: 0
Well actually it thinks you'd want to source the file "cd". thats the problem.

Im just thinking about a way to reach what you want whithout a script. If it helps, create a file

Code:
cd xxzzy
, name it test and source it

Code:
. test
 
Old 05-27-2009, 08:23 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You need to put the cd cmd inside the script, and source (or dot space) the script.
 
Old 05-27-2009, 09:04 PM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
You can't,

Use an alias, a function or source your script as suggested above.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
su - and stay in current dir lord-fu Linux - Newbie 2 11-16-2005 08:08 AM
how could i make a user stay in his or home dir Paxmaster Linux - General 1 03-23-2005 09:10 PM
stupid bash question tisleti Linux - Newbie 4 09-10-2004 05:34 AM
simple bash question -- changing dir towlie Programming 3 05-28-2004 11:55 AM
bash script - even more stupid question than last time. webamoeba Linux - Newbie 2 02-12-2004 03:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:27 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
Open Source Consulting | Domain Registration