0

I want to count the lines of a file in a folder with a space in its name. I unfortunately cannot change the folder name, it will always have a space in it.

$ export MYPATH=a\ folder/trigrams.txt
$ wc -l $MYPATH
wc: a: open: No such file or directory
wc: folder/trigrams.txt: open: No such file or directory
       0 total

$ export MYPATH="a\ folder/trigrams.txt"
$ wc -l $MYPATH
wc: a\: open: No such file or directory
wc: folder/trigrams.txt: open: No such file or directory
   0 total

$ wc -l "$MYPATH"
wc: a\ folder/trigrams.txt: open: No such file or directory

$ wc -l a\ folder/trigrams.txt 
70803 a folder/trigrams.txt
2
  • wc -l "$MYPATH" Commented Apr 24, 2020 at 15:50
  • You have to assign like MYPATH='a folder/trigrams.txt' and then use wc -l "$MYPATH"; you added a literal backslash in your latest edit. Commented Apr 24, 2020 at 15:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.