Image

Imageian_poncho wrote in Imagelinux

Shell expansions in command lines

Hi,

I'm writing a C application, which accepts a command-line argument like:

./app --file=/home/foo/file.txt

If the specified file doesn't exist, then the app creates it and writes to it.

The problem I have comes when a user types:

./app --file=~/file.txt

In this case, instead of expanding the ~/file to /home/foo/file.txt - my application is creating a directory called ~ and a file within it! Doh..

I see 2 solutions.

1. Write code inside my app to detect ~ and expand it using the HOME environment variable.
2. ???

My gut tells me that this is a problem that I shouldn't have to solve - and should be handled at the shell level. But bash only does tilde expansion at the start of a word (http://www.gnu.org/software/bash/manual/bashref.html#SEC28) and my tilde will always be preceded by a --file= prefix.

Any ideas??