Search code examples
bashvisual-studio-codeautomationcommand-line-interface

VSCode CLI in bash script while loop to open multiple files


I'm trying to use VSCode cli code in a while loop in a Bash script to open a number of files, the names of which I'm reading from a text file.

When I run the code below, it opens a file correctly for the first line from the file I'm reading, and then it opens a file like code-stdin-XXX that is a list of the rest of the lines from filenames.txt. If I change code to echo in the script this runs fine, so I assume I'm missing something in the code cli options.

while read -r line ; do
    code - "../songs/$line.xhtml"
done < filenames.txt

How I can correctly get code to open the file for each line of filenames.txt?


Solution

  • for line in $(cat filenames.txt); do
        code "../songs/$line.xhtml"
    done