Using the result of a command as an argument in bash? -


to create playlist of music in folder, using following command in bash:

ls > list.txt 

i use result of pwd (print working directory) command name of playlist.

something like:

ls > ${pwd}.txt 

that doesn't work though - can tell me syntax need use this?

edit: mentioned in comments pwd end giving absolute path, playlist end being named .txt in directory - d'oh! i'll have trim path. spotting - have spent ages wondering files went!

use backticks substitute result of command:

ls > "`pwd`.txt" 

as pointed out landon, $(cmd) equivalent:

ls > "$(pwd).txt" 

note unprocessed substitution of pwd absolute path, above command creates file same name in same directory working directory, .txt extension. thomas kammeyer pointed out basename command strips leading directory, create text file in current directory name of directory:

ls > "`basename "$(pwd)"`.txt" 

also erichui bringing problem of spaces in path.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -