LinuxQuestions.org
Register a domain and help support LQ
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
 
LinkBack Search this Thread
Old 08-24-2006, 05:00 AM   #1
Roger Krowiak
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 33

Rep: Reputation: 15
BASH: cannot enter special-named dir from script


I have created some directories with exotic names, read them from script and then I try to enter them using:

cd "$i"

where in i is stored ine single directory. When the directory name is dash - the script will made jump to the previous working directory. I've found in BASH manual that cd - will move you to the previus directory (from directory stack). I know how to workaround this from command line using cd \- but how can I do it from script using cd "$i"? Thank you for help.
 
Old 08-24-2006, 06:10 AM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 3,992

Rep: Reputation: 478Reputation: 478Reputation: 478Reputation: 478Reputation: 478
If I remember well you can access or list files starting with a dash with "./-myfile". In your case, it would be "./$i".

If this doesn't work, there is a thread on this forum dealing with such an access problem, but I am not able to find it now.

jlinkels
 
Old 08-24-2006, 06:14 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,543
Blog Entries: 51

Rep: Reputation: 2606Reputation: 2606Reputation: 2606Reputation: 2606Reputation: 2606Reputation: 2606Reputation: 2606Reputation: 2606Reputation: 2606Reputation: 2606Reputation: 2606
That's right. Since you don't use a full path you mean to say "in the current working directory" or "./-".
Here's an example of a check for it:
Code:
function pathCheck() { [ "${i:0:1}" != "/" -a -d "$PWD/$i" ] && i="$PWD/$i"; }

Last edited by unSpawn; 08-24-2006 at 06:21 AM. Reason: //fix
 
Old 08-24-2006, 06:19 AM   #4
Roger Krowiak
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 33

Original Poster
Rep: Reputation: 15
Thank you both for help, it works now correctly!
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script test for empty dir uopjohnson Linux - Software 3 10-07-2005 06:45 PM
Bash script to compare dir contents Boffy Programming 2 08-02-2005 06:08 AM
Testing for enter in bash script bwysocki Programming 8 06-16-2005 09:11 AM
Trying to read named.conf forwarders info in bash script. scottman Programming 4 09-11-2004 09:38 PM
bash script to rm all files in a dir keirobyn Programming 8 07-19-2002 07:53 AM


All times are GMT -5. The time now is 10:16 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration