オープンソースソフトウェアの一つの大きな利点は、あなたが(私はバージョン4.2で探しています)、含まれていy.tab.c
ファイルがありますbash
用のコードをダウンロードする場合、ソースは、よく、オープン:-)
であるということですdecode_prompt_string()
機能:
char *decode_prompt_string (string) char *string; { ... }
あなたは(一緒にとのいずれかがサポートルーチンを必要とすることを抽出して、あなたのために仕事をした実行ファイルをビルドしようとすることができぞんざいな試みから、これらのサポートルーチンがたくさんあるように見える、けれども。 、これは難しい作業かもしれません。
それ以外は
、あなたはおそらくのようなもので、あなたのためにそれを拡大するに「トリック」bash
ことができます。
expPS1=$(echo xyzzyplughtwisty | bash -i 2>&1
| grep xyzzyplughtwisty
| head -1
| sed 's/xyzzyplughtwisty//g')
は今、私は読みやすくするために、複数行に渡って置かれているが、それは、一つに行われましたライン。
これは、無効なコマンドを渡す(うまくいけば)bash
のインタラクティブなインスタンスを実行します。
対話型なので、プロンプトが表示されるので、最初の行にコマンド文字列をつけて、コマンド文字列を削除します。残されているのはプロンプトです。
pax> expPS1=$(echo xyzzyplughtwisty | bash -i 2>&1 | grep xyzzyplughtwisty | head -1 | sed 's/xyzzyplughtwisty//g')
pax> echo "[$expPS1]"
[pax> ]
pax>
しかし、これは、実際に現在のシェル1のではなく、あなたの通常のプロンプトを与えるプロンプト複数行に問題があります。私のシステムで
が、これは私が得るものです。
あなたはそれが正しく、は、それ自体bash
に少し追加伴うこと行いたい場合は
。次に、内部コマンドevalps1
を追加する手順を示します。 まず、あなたがbash
「本物」と混同しないであろう、とFSFは、単に1行を変更:-)保証の目的のために、すべての知識を拒否することができるようにというように(私は-pax
ビットを追加しました)support/mkversion.sh
を変更します。
echo "#define DISTVERSION \"${float_dist}-pax\""
次に、 `builtins/Makefile.in 'を変更して新しいソースファイルを追加します。これにはいくつかのステップが必要です。
(a)DEFSRC
の末尾に$(srcdir)/evalps1.def
を追加します。
(b)evalps1.o
をOFILES
の末尾に追加します。
(c)に必要な依存関係を追加します。
This file is evalps1.def, from which is created evalps1.c.
It implements the builtin "evalps1" in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES evalps1.c
$BUILTIN evalps1
$FUNCTION evalps1_builtin
$SHORT_DOC evalps1
Outputs the fully interpreted PS1 prompt.
Outputs the PS1 prompt, fully evaluated, for whatever nefarious purposes
you require.
$END
#include <config.h>
#include "../bashtypes.h"
#include <stdio.h>
#include "../bashintl.h"
#include "../shell.h"
#include "common.h"
int
evalps1_builtin (list)
WORD_LIST *list;
{
char *ps1 = get_string_value ("PS1");
if (ps1 != 0)
{
ps1 = decode_prompt_string (ps1);
if (ps1 != 0)
{
printf ("%s", ps1);
}
}
return 0;
}
バルク:
evalps1.o: evalps1.def $(topdir)/bashtypes.h $(topdir)/config.h \
$(topdir)/bashintl.h $(topdir)/shell.h common.h
第三に、builtins/evalps1.def
ファイル自体を追加し、これはあなたがevalps1
コマンドを実行したときに実行されますコードですそのうちGPLライセンス(exit.def
から変更したものです)は最後に非常に単純な関数で、PS1
を取得してデコードします。
最後に、ちょうどトップレベルのディレクトリにものを構築する:
./configure
make
私はそれが今まで
:-)その祖先と同じくらい普及しないだろうけれども表示されますが、paxsh
に名前を変更することができbash
そして、それを実行している、あなたはアクションでそれを見ることができます。今すぐ
pax> mv bash paxsh
pax> ./paxsh --version
GNU bash, version 4.2-pax.0(1)-release (i686-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
pax> ./paxsh
pax> echo $BASH_VERSION
4.2-pax.0(1)-release
pax> echo "[$PS1]"
[pax> ]
pax> echo "[$(evalps1)]"
[pax> ]
pax> PS1="\h: "
paxbox01: echo "[$PS1]"
[\h: ]
paxbox01: echo "[$(evalps1)]"
[paxbox01: ]
、付与された、追加するbash
にコードの変更を行いますいくつかの内部コマンドは過剰なものと見なされるかもしれませんが、正確な評価がPS1
の場合は、確かにオプションです。
おそらく他の人が知っているかもしれませんが、私はあなたが何を話しているのか分かりません。あなたは何を達成しようとしていますか? – Kurt
$ PS1、$ PS2を評価しますか?または、スクリプト内の変数に値を属性付けしますか? – Gangadhar
'evaluate'という関数やコマンドがあるとします。 'PS1の評価'の結果はどうあるべきですか? –