LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
 
Search this Thread
Old 08-24-2006, 06: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, 07:10 AM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,244

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
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, 07:14 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,777
Blog Entries: 54

Rep: Reputation: 2977Reputation: 2977Reputation: 2977Reputation: 2977Reputation: 2977Reputation: 2977Reputation: 2977Reputation: 2977Reputation: 2977Reputation: 2977Reputation: 2977
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 07:21 AM. Reason: //fix
 
Old 08-24-2006, 07: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


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


All times are GMT -5. The time now is 01:00 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration