LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-25-2008, 06:13 PM   #1
miceagol
LQ Newbie
 
Registered: Oct 2004
Location: Oslo, Norway
Distribution: Ubuntu
Posts: 27

Rep: Reputation: 15
[solved] Bash script: Parse folders in path string


I have a variable ${4} which is a path, e.g. /home/user/backup/music/artist/album/, and I would like to parse each folder from this path into individual strings. The number of folders to parse may be different each time, so the code must be able to continue parsing until there's nothing more to parse.

When I have parsed the folder, I want to check if it exists in that position of the folder tree, and if it does not exist I want to create it. E.g. the code has parsed music, and must then check if music exists in /home/user/backup/, and if not, then create it. If this task can be performed within the loop described in the last paragraph, then it is not necessary to keep each folder string.

I hope this is a nice challenge for you, and please ask if you lack any info.

Last edited by miceagol; 03-26-2008 at 03:38 AM.
 
Old 03-25-2008, 06:24 PM   #2
cmnorton
Member
 
Registered: Feb 2005
Distribution: Ubuntu, CentOS
Posts: 585

Rep: Reputation: 35
More info

How about posting some of what you've got already, like the input data, the script and so on?
 
Old 03-25-2008, 06:26 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Code:
mkdir -p $4
 
Old 03-25-2008, 06:31 PM   #4
miceagol
LQ Newbie
 
Registered: Oct 2004
Location: Oslo, Norway
Distribution: Ubuntu
Posts: 27

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by colucix View Post
Code:
mkdir -p $4
Lol! I had to laugh. Somtimes it's just too hard to think simple. Thanks a lot!
 
  


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
Parse String in a Bash script jimwelc Linux - Newbie 8 11-09-2012 07:47 AM
How to parse full path of file name in bash ? hq4ever Programming 2 03-28-2005 03:31 PM
Parse RPM version string in Bash jimwelc Linux - Newbie 1 02-28-2005 05:22 PM
bash script help to parse out text slack guy Linux - Newbie 3 12-30-2004 08:42 AM
Newbie bash path parse problem ericcarlson Linux - Newbie 4 08-05-2004 10:43 AM

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

All times are GMT -5. The time now is 05:55 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
Open Source Consulting | Domain Registration