「Transwiki:Bash Shell Scripting」の版間の差分

削除された内容 追加された内容
Fu7mu4 (トーク | 投稿記録)
Fu7mu4 (トーク | 投稿記録)
714 行
出力内容: <pre>/&#xA;/&#xA;/home&#xA;/</pre>
 
{{Transwiki:Bash Shell Scripting/tip|もしあなたのスクリプトが与えられたコマンドを実行する前に現在ディレクトリを変更する必要がある場合、可能であればサブシェルはよいアイディアです。サブシェルを使用しない場合、スクリプトを読み間常に現在ディレクトリを追跡しなければなりません。(代替方法としては、ビルトインコマンドの <tt>pushd</tt> と<tt>popd</tt>があり、類似した効果が得られます。)}}
{{Transwiki:Bash Shell Scripting/tip|If your script needs to change the working directory before running a given command, it's a good idea to use a subshell if possible. Otherwise it can become hard to keep track of the working directory when reading a script. (Alternatively, the <tt>pushd</tt> and <tt>popd</tt> built-in commands can be used to similar effect.)}}
 
サブシェル内の<tt>exit</tt>ステートメントはそのサブシェルだけを終了させます。また例を挙げます。:
An <tt>exit</tt> statement within a subshell terminates only that subshell. For example, this script:
 
<source lang="bash">#!/bin/bash
723 行
</source>
 
prints this表示内容: <pre>subshell succeeded&#xA;subshell failed</pre>
 
Like in a script as a whole, <tt>exit</tt> defaults to returning the exit status of the last-run command, and a subshell that does not have an explicit <tt>exit</tt> statement will return the exit status of the last-run command.