論點我去尋找類似的東西,可能就是找不到它,所以我做了以下兩個腳本。首先,說shellstate
,然後可能至少set -i
和set -o emacs
這reset_shellstate
不會爲你做。我不知道一種方法來問問bash它認爲哪些變量是特殊的。
~/bin/reset_shellstate
:
#!/bin/bash
__="$PWD/shellstate_${1#_}"
trap '
declare -p >"'"$__"'"
trap >>"'"$__"'"
echo cd \""$PWD"\" >>"'"$__"'" # setting PWD did this already, but...
echo set +abefhikmnptuvxBCEHPT >>"'"$__"'"
echo set -$- >>"'"$__"'" # must be last before sed, see $s/s//2 below
sed -ri '\''
$s/s//2
s,^trap --,trap,
/^declare -[^ ]*r/d
/^declare -[^ ]* [A-Za-z0-9_]*[^A-Za-z0-9_=]/d
/^declare -[^ ]* [^= ]*_SESSION_/d
/^declare -[^ ]* BASH[=_]/d
/^declare -[^ ]* (DISPLAY|GROUPS|SHLVL|XAUTHORITY)=/d
/^declare -[^ ]* WINDOW(ID|PATH)=/d
'\'' "'"$__"'"
shopt -op >>"'"$__"'"
shopt -p >>"'"$__"'"
declare -f >>"'"$__"'"
echo "Shell state saved in '"$__"'"
' 0
unset __
~/bin/shellstate
:
#!/bin/bash
shellstate=shellstate_${1#_}
test -s $shellstate || reset_shellstate $1
shift
bash --noprofile --init-file shellstate_${1#_} -is "[email protected]"
exit $?
我需要做一些工作用C a.sh和b.sh的執行之間,所以這是不可能的,以B鍵。請注意,我對shell變量感興趣,而不是環境變量。 – danvk 2010-07-11 17:38:03
啊,對不起! – eruciform 2010-07-11 18:41:36