-
Notifications
You must be signed in to change notification settings - Fork 0
Home
season1618 edited this page Mar 13, 2024
·
2 revisions
コマンドの構造は以下の通り。fork
はPipe
の実行時、exec
はSimple
の実行時に限られる。Pipe
の直下はRedirCmd
であり、RedirCmd
の直下はPrimCmd
であることから、サブシェルを除きシェルで実行されるプロセスは全てシェルの直接の子プロセスとなる。
pub enum Command {
Sequence { lhs: Box<Command>, rhs: Box<Command> },
BranchAnd { lhs: Box<Command>, rhs: Box<Command> },
BranchOr { lhs: Box<Command>, rhs: Box<Command> },
Pipe(Vec<RedirCmd>),
}
pub struct RedirCmd {
pub cmd: Box<PrimCmd>,
pub input: Option<String>,
pub output: Option<WriteMode>,
}
pub enum PrimCmd {
Subshell(Box<Command>),
Simple { name: String, args: Vec<String> },
}
-p
オプションでプロンプトを非表示にする。
bashなどのシェルにはinteractiveとnon-interactiveというのがあり、標準入出力が端末でない場合はnon-interactiveとしてプロンプトを表示しないようになっている。 Interactive Shells (Bash Reference Manual)
シェルは通常ファイル終端を表すEOF(Ctrl-D)で終了するようになっている。したがってシェルにリダイレクトでファイルを渡したり、echoコマンドからパイプで標準入力につないでコマンドを渡すと、コマンド実行後即座に終了する。
プロンプトが非表示の場合はそのまま終了、プロンプトが表示されている場合は改行して終了。
linuxのsh
と自作シェルの結果を比較する。
test() {
input="$1"
expected=`echo $input | sh`
actual=`echo $input | target/debug/ttsh -p`
if [ "$expected" == "$actual" ];
then
echo "OK"
else
echo "$input: expected $expected, actual $actual"
fi
}