Date: Tue, 7 Jun 2016 20:06:05 +0200 From: Polytropon <freebsd@edvax.de> To: Murk Fletcher <murk.fletcher@gmail.com> Cc: User Questions <freebsd-questions@freebsd.org> Subject: Re: rc scripting trouble with quotes Message-ID: <20160607200605.6761fc0e.freebsd@edvax.de> In-Reply-To: <CAH=3fONuy_afgSHGMO7YafN2cX8O9V9ULV3-%2BQq86eRxaJXysw@mail.gmail.com> References: <CAH=3fONuy_afgSHGMO7YafN2cX8O9V9ULV3-%2BQq86eRxaJXysw@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 7 Jun 2016 14:04:27 +0200, Murk Fletcher wrote: > Hi! > > How do I access a variable inside quotes? Right now I'm having some > difficulties: > > stop_cmd="cd ${myapp} && \ > ${myapp} stop && \ > kill -9 `cat ${myapp}/tmp/pids/example.pid`" > > Returns: > > cat: ${myapp}/tmp/pids/example.pid: No such file or directory Have you checked the actual value of that expression? For testing, insert something like echo ${myapp}/tmp/pids/example.pid to see if you _really_ get the file name you're expecting. > I hear it would work better with double quotes, [...] There is no "work better" here: If you use double quotes, variables will be expanded; if you use single quotes, they will not. Double quotes are usually needed when a path contains spaces (because the space character is the argument separator, while it also is a valid character for file names). > [...] but that would add a > double-double quote at the end: > > stop_cmd="cd ${myapp} && \ > ${myapp} stop && \ > kill -9 "$(cat -- ${myapp}/tmp/pids/example.pid)"" You could use qupting, \", but that probably won't work as intended. You need to use quotes because the value you assign to $stop_cmd contains spaces. You could use quoted spaces, \ , to get rid of them, but that makes the whole thing nearly unreadable and will probably introduce more problems. :-) > Is there a way I could wrap the contents of `stop_cmd` inside a function or > something? Basically, your initial assignment looks correct, there surely is a different problem (maybe with the evaluation of ${myapp}. As it as already been mentioned, /etc/rc.subr should do what's needed to stop a program, maybe you don't even need to do this manually. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160607200605.6761fc0e.freebsd>