Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all directories comma separated and send output to other script

Tags:

linux

bash

We use phpDocumentator to document our php code. The php code is in different dictionaries. The script which runs the phpDocumentator looks like this:

./phpdoc -d dir1,dir2,dir3,dir4  

Every time we add a new directory, I have to add this one to the script.

I would like to do this dynamically.

ls -d ../*test*  

this lists all needed directories but space separated and not comma separated.

Question:

How can I list the directories comma separated?

how can I add this list as -d parameter to the phpdoc script?

like image 656
mjspier Avatar asked May 13 '11 12:05

mjspier


People also ask

What options to ls will result in comma separated list of entries?

Linux ls command can output the contents of a directory separated by comma when used with the switch (-m).

How do you write a command that lists all the files and directories of the current directory separated by commas?

You can use the GNU ls -m command. It will print all files and dir separated by comma.

How copy all files and subdirectories in Unix?

Copying Directories with cp Command To copy a directory, including all its files and subdirectories, use the -R or -r option. The command above creates the destination directory and recursively copy all files and subdirectories from the source to the destination directory.


1 Answers

Use ls -dm */ to generate a comma-separated list of directories. -d will return directories only and -m will output to a comma-separated list.

You could then store the output in a variable and pass it along as an argument:

#!/bin/bash MY_DIRECTORY=/some/directory FOLDERS=`ls -dm $MY_DIRECTORY/*/ | tr -d ' '` phpdoc -d $FOLDERS 
like image 50
Aron Rotteveel Avatar answered Sep 29 '22 23:09

Aron Rotteveel