Escaping singlequote in random filenames

349 Views Asked by At

I have a simple bash script which outputs the total file size using 'du' However every time I pass a file that contains an apostrophe it presents me with a syntax error. So I'd like to know if there was a way to escape singlequotes without modifying the filenames. Preferably before diskusage processes them.

The code is:

du -chs {query}

I use Alfred to pass the files into the script. The application allows the user to escape a few characters but the single quote is not one of them.

1

There are 1 best solutions below

0
On

Try wrap the file names in double quotes, that seems to work for me:

With a file named hello'world among a few others:

du -chs hello*

Gives:

4.0K    hello.RST
4.0K    hello.txt
4.0K    hello'world
12K     total