This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Portable shell code between Cygwin and Linux

On Mon, Aug 1, 2011 at 8:49 AM, Sebastien Vauban? wrote:
> Hi Andrey,
> Andrey Repin wrote:
> >>> For every shell code that I write, I'd like it to be portable both to
> >>> Cygwin on Windows, and to Ubuntu Linux for example.
> >>>
> >>> It's kinda possible, but am blocked with such a use case:
> >>>
> >>> alias vpnup='exec sudo openvpn --config ~/config/client.vpn --writepid /tmp/ &'
> >>>
> >>> While this worked perfectly under Ubuntu, I've had to make up a customized
> >>> version for Windows:
> >>>
> >>> alias vpnupwin='cd c:/home/sva/config; openvpn --config client.vpn --writepid c:/cygwin/tmp/ &'
> >
> >> Don't use Win32 paths. ?Use POSIX paths:
> >
> >> ? alias vpnupwin='cd /cygdrive/c/home/sva/config; openvpn --config client.vpn --writepid /cygdrive/c/cygwin/tmp/ &'
> >
> > Moreover, the very first line is wrong.
> >
> > Must be
> >
> > alias vpnup='exec sudo openvpn --config $HOME/config/client.vpn --writepid /tmp/ &'
> >
> > that's where his problem began, IMO.
> That's interesting. I thought this was completely equivalent (~ or $HOME), and
> preferred the shorter version.
> But you say it's not. Can you comment on this? ?Thanks in advance...
> Tilde expansion:
"If a word begins with an unquoted tilde character (`~'), all of the
characters up to the first unquoted slash (or all characters, if there
is no unquoted slash) are considered a TILDE-PREFIX."

Note "word begins". I've been bitten by this in a makefile:

OPENSSL_DIR := ~/lib/openssl

The gcc command line then contained -I~/lib/openssl, and the ~ was not
expanded by the shell. ${HOME}/lib/openssl would have worked.

If you want the same alias to work on Cygwin and Linux, you should set
up your $HOME on Cygwin to contain config/client.vpn
You can set your home in /etc/passwd and point it to /cygdrive/c/home
(this may have been mentioned already).
The idea is to always refer to the VPN config as
${HOME}/config/client.vpn and ensure that Cygwin can access it that

Hope this helps,
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]