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
?
2
Answers
This is all you need:
xargs
: Reads file names fromSTDIN
(filenames.txt
) and pass them as argument to the command.code --
: Executescode
with options stopper--
andxargs
will append filenames as arguments.