LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-11-2005, 05:13 PM   #1
kevpatts
LQ Newbie
 
Registered: May 2004
Posts: 24

Rep: Reputation: 0
Basic bash script question


I have 4 folders in /Audio named:

Albums
Compilations
Singles & EPs
Audio Books

I'm looking for a bit of bash script that can create an files from these using the command something like:

touch ${DIRS[index]}.txt

Can anyone help?
Kev
 
Old 10-11-2005, 05:52 PM   #2
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
Code:
for x in /Audio/*
do
   test -d "$x" && touch "$x.txt"
done
or on one line:

Code:
for x in /Audio/*; do test -d "$x" && touch "$x.txt"; done
Will create one empty .txt file for each directory in /Audio.

...is that what you were asking?
 
Old 10-12-2005, 08:07 AM   #3
kevpatts
LQ Newbie
 
Registered: May 2004
Posts: 24

Original Poster
Rep: Reputation: 0
Thanks,

That's close, but not quite it. I'm looking to put the values onto an array in such a way as the can be used many times. Also in such a way that when I use:
touch ${DIRS[index]}.txt

when the array entry is "Singles & EPs" I get "Singles & EPs.txt" instead of:

Singles.txt
&.txt
EPs.txt

That's what I currently get.

Thanks for the help.
Kev
 
Old 10-12-2005, 02:02 PM   #4
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
Code:
i=0

for x in /Audio/*
do
   test -d "$x" &&  DIRS[$i]="$x"
   i=$(($i+1))
done
Would load an array with all the directories in /Audio.

Because of the spaces in some of your directory names, you'll need to reference the array elements from within quotes like:

touch "${DIRS[index]}.txt"

to keep bash from splitting the array element at its spaces.

If this still isn't what you're asking for, maybe you could post your current code?
 
  


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
Basic Bash script help valadamir Programming 2 12-01-2004 11:37 AM
Trouble with a basic bash script Tengil Linux - Newbie 5 03-04-2004 01:59 PM
Basic BASH scripting question Dark_Helmet Programming 3 06-26-2003 06:45 PM
Basic BASH script, what's wrong??? Satriani Linux - General 2 06-02-2003 06:34 PM
help with basic syntax in bash script Supp0rtLinux Linux - Software 4 03-27-2003 07:57 PM


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