0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

サブシェル内における変数

Last updated at Posted at 2020-01-31

こんにちは。
サブシェル内における変数の設定は元シェルへは反映されないです(ローカルスコープ扱い)。下記例は、括弧「( )」で囲われ(そしてその値を取り出し)ているので、サブシェルで実行されます。

$ m=$(n=1); echo $n

$

これに対して、算術結果値を得る $((...))) の形式は、サブシェルではないので、変数設定は反映されます。

$ m=$((n=1)); echo $n
1
$
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?