LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-06-2005, 12:45 PM   #1
gtwilliams
LQ Newbie
 
Registered: Jun 2005
Distribution: ubuntu - hoary hedgehog
Posts: 13

Rep: Reputation: 0
Bash Scripting Directories with Spaces


I am having a hell of a time figuring out how to script something in BASH -
Specifically directories with spaces!!!
So the backslash is an escape character? How do I navigate spaced directories?

#!/bin/bash
DIRECTORY=/some\ music/

echo cd $DIRECTORY #the echo is cd /some music/
cd $DIRECTORY


so maybe i'll try:
DIRECTORY=/some\\ music/
echo cd $DIRECTORY #the echo is music/: no such file or directory
cd $DIRECTORY

i've tried quoting it ; triple slashing it ; nothing seems to be working
what's the deal?? I got one of the commands to echo the right setup:
cd /some\ music/

but when i had the actualy command cd $DIRECTORY it erred and said :
directory: /some\ not found !

any ideas?
 
Old 07-06-2005, 12:47 PM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 270Reputation: 270Reputation: 270
Try with quotes instead
 
Old 07-06-2005, 01:01 PM   #3
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
Replace
Code:
DIRECTORY=/some\ music/
With
Code:
DIRECTORY="some music"
And use cd as follows

Code:
cd "$DIRECTORY"
 
Old 07-06-2005, 03:16 PM   #4
gtwilliams
LQ Newbie
 
Registered: Jun 2005
Distribution: ubuntu - hoary hedgehog
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks - looks like its working !
 
  


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
moving files that have spaces in variables -bash scripting bhar0761 Programming 10 09-22-2005 07:30 AM
bash scripting: filenames with spaces joanq Programming 2 05-24-2005 12:50 PM
BASH scripting problem, spaces in filenames / using basename textures Programming 24 11-16-2003 01:41 AM
Directories with spaces Blitzkrieg Linux - General 4 11-28-2002 03:41 PM
BASH scripting browsing multiple directories PokerFace Programming 3 10-02-2002 12:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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