From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16315 invoked by alias); 3 Dec 2015 12:56:08 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37283 Received: (qmail 18241 invoked from network); 3 Dec 2015 12:56:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f4-f79026d00000418a-a8-566039870ebf Date: Thu, 03 Dec 2015 12:45:54 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: a way to get the value of the -c option Message-id: <20151203124554.3b93281f@pwslap01u.europe.root.pri> In-reply-to: <20151203115449.GA19846@zira.vinc17.org> References: <20151203115449.GA19846@zira.vinc17.org> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrALMWRmVeSWpSXmKPExsVy+t/xa7rtlglhBr9eslgcbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujCOTFjMWzOau+Nd4lr2BcSJnFyMnh4SAicS6uavZIWwxiQv3 1rN1MXJxCAksZZRYM+EfC4Qzg0niyc1djBDOaUaJUysuMEM4Zxglms4tAyrj4GARUJXoW5AN MopNwFBi6qbZjCC2iIC4xNm151lAbGGgdZdbtjKB2LwC9hKrLu8Ei3MKmEq8OPGYGcQWAqpZ 3bIdrJdfQF/i6t9PTBDn2UvMvHKGEaJXUOLH5HtgvcwCWhKbtzWxQtjyEpvXvIWaoy5x4+5u 9gmMwrOQtMxC0jILScsCRuZVjKKppckFxUnpuYZ6xYm5xaV56XrJ+bmbGCHh/GUH4+JjVocY BTgYlXh4BTzjw4RYE8uKK3MPMUpwMCuJ8H5bCxTiTUmsrEotyo8vKs1JLT7EKM3BoiTOO3fX +xAhgfTEktTs1NSC1CKYLBMHp1QDY0LERavu3n2fdFVE0jdtqZ/Bzbr9b8sz7x/WE1uELk1q msZ7MsMpMvySUb1C/MTvd+1mTY4qNhaa/DjslZXHgTlLdFrLTx6qOb4t2Nc974Lm+S5tz4dG Qma3Xz7wKlwZHbbzokl8z0+RhG9cpcd5OnWjBWUOxPIInv25Luoad56IfrPin8kaSizFGYmG WsxFxYkAJ7fU72MCAAA= On Thu, 3 Dec 2015 12:54:49 +0100 Vincent Lefevre wrote: > zsh should provide a way to get the value of the -c option. Under > Linux, one can look at /proc/$$/cmdline, but I think that it would > be better to get this information in an OS-independent way. This would be easy to do like this, for example, which has the benefit of being trivial. It's already possible to detect the shell was started like this with zsh_eval_context[1], so another possibility might be to combine it with a more generic way of getting top-level values. pws diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 21bb874..8ef5485 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -933,6 +933,11 @@ tt(zsh/zutil) module. ) enditem() ) +vindex(ZSH_CMD_ARG) +item(tt(ZSH_CMD_ARG))( +If the shell was started with the option tt(-c), this contains +the argument passed to the option. Otherwise it is not set. +) vindex(ZSH_NAME) item(tt(ZSH_NAME))( Expands to the basename of the command used to invoke this instance diff --git a/Src/init.c b/Src/init.c index dcce1d7..25c39b5 100644 --- a/Src/init.c +++ b/Src/init.c @@ -1280,6 +1280,7 @@ init_misc(void) fclose(bshin); SHIN = movefd(open("/dev/null", O_RDONLY | O_NOCTTY)); bshin = fdopen(SHIN, "r"); + setsparam("ZSH_CMD_ARG", ztrdup(cmd)); execstring(cmd, 0, 1, "cmdarg"); stopmsg = 1; zexit(lastval, 0);