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

前端 未结 7 1858
野趣味
野趣味 2020-12-04 13:52

To create a playlist for all of the music in a folder, I am using the following command in bash:

ls > list.txt

I would like to use the r

7条回答
  •  甜味超标
    2020-12-04 14:42

    I suspect the problem may be that there are spaces in one of the directory names. For example, if your working directory is "/home/user/music/artist name". Bash will be confused thinking that you are trying to redirect to /home/user/music/artist and name.txt. You can fix this with double quotes

    ls > "$(pwd).txt"
    

    Also, you may not want to redirect to $(pwd).txt. In the example above, you would be redirecting the output to the file "/home/user/music/artist name.txt"

提交回复
热议问题