LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 11-07-2006, 06:52 AM   #1
paulyche
LQ Newbie
 
Registered: Apr 2006
Posts: 6

Rep: Reputation: 0
escaping ':' character in bash script


I've written my first bash script for backing up my music album by album onto an external FAT32 drive.

Code:
#!/bin/bash
# Music collection backup script
# Each album folder goes into one tar.gz file in target location (because of 4gb limit in fat32)
# Each album added is appended to album_list - simple text file in target dir
# Gzipping is a waste of time. The gain over mp3 compression is negilible

backup_dir=/media/IOMEGA_HDD/linux_backup/music_collection
music_dir=/home/paul/music/collection
album_list=/$backup_dir/album_list
touch $album_list

cd $music_dir

for album in *
do
if [ -f $backup_dir/"$album" ]
then
  echo $album is already backed up
else
  tar -cf $backup_dir/"$album" "$album"
  echo $album >> $album_list
It generally works as expected even with filenames full of spaces. My problem lies with albums with ':' characters in the title:

Which give the following error:
Code:
tar: /media/IOMEGA_HDD/linux_backup/music_collection/Mogwai-Government Commissions\: BBC Sessions 1996-2003: Cannot open: Invalid argument
It's nothing to do with the file length. I wonder if enclosing in "" doesn't allow you to escape two non-standard characters in a row?

Any ideas? I'd rather not change all my filenames, because I'd rather a robust script that works with a variety of stuff.
 
Old 11-07-2006, 07:02 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
I think this is probably because FAT file-systems can't contain files with a : in them - it's used to denote a drive name in MSDOS, e.g.
Code:
D:
 
Old 11-07-2006, 07:18 AM   #3
paulyche
LQ Newbie
 
Registered: Apr 2006
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by matthewg42
I think this is probably because FAT file-systems can't contain files with a : in them - it's used to denote a drive name in MSDOS, e.g.
Code:
D:
Mmmm good point. I hadn't though of that.
 
  


Reply

Tags
bash, escape


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatic special character escaping in Bash scripts? wipe Linux - Software 1 06-05-2009 06:41 PM
Remove rightmost character from bash gn00kie Programming 9 01-29-2008 12:08 AM
Bash script - escaping whitespaces colabus Linux - Newbie 15 04-29-2006 11:58 PM
perl post character escaping kapilcool Programming 3 12-20-2005 07:42 AM
NOT escaping bash history ivanatora Linux - General 3 06-07-2005 01:17 PM


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