1

I need to execute a command in bash that takes a constructed argument. The string argument needs to be passed without quotations. How do I remove the quotes?

This does not work:

Tracks='bark.mov'
TrackDir='~/soundtracks/'
TrackPath=$TrackDir$Track
omxplayer -o local $TrackPath

This does not work:

omxplayer -o local '~/soundtracks/bark.mov'

This does work:

omxplayer -o local ~/soundtracks/bark.mov
2
  • 2
    @PatrickHaugh Double quotes also prevent tilde expansion. Commented Jun 3, 2018 at 0:17
  • 1
    TrackDir=~/'soundtracks/' Commented Jun 3, 2018 at 0:37

2 Answers 2

3

Tilde expansion only works outside of quotes. Get rid of the quotes when defining the variables, but do include quotes when expanding them.

Tracks=bark.mov
TrackDir=~/soundtracks/
TrackPath=$TrackDir$Track
omxplayer -o local "$TrackPath"
Sign up to request clarification or add additional context in comments.

Comments

1

You need to leave the ~ unquoted so that the shell can expand it to the user's home directory. Further, it's better practice to add the path separator when you join the two, to make it explicit. Having two adjacent / in the path doesn't hurt.

Tracks=bark.mov
TrackDir=~/soundtracks/
TrackPath=$TrackDir/$Track
omxplayer -o local "$TrackPath"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.