Shell Script Problem With Escaping Spaces in Variables

Hi there,

I'm having an issue where I'm trying to use the command line to access a particular file with ffprobe. It gets tripped up on the spaces in my file path so I need some way of escaping them. This works:

However I need to store the path information in variables. This is where I run into issues because this doesn't work:

I get the error "No such file or directory"

Something like this also doesn't work:

I get the error: "Argument 'LAMAR/withoutwarningnewyork_Classic_album_incoming_kendricklamar_theheartpart5_topimpabutterfly_.mp4'' provided as input filename, but '‘/Users/macpro3/Downloads/_VIDEOS/RIPS/REEL/KENDRICK' was already specified."

I'm far from being an expert on the command line or shell scripts so maybe this is really obvious but any thoughts would be super appreciated.

Your second example is close, but single quotes in the shell take everything inside them literally, including the variables you want to expand out to their values. Use double quotes instead.

1 Like

Ah brilliant, thanks so much!