LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 05:00 AM   #1
Roger Krowiak
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 38

Rep: Reputation: 18
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
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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: 38

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


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
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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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