LoginSignup
0
0

More than 1 year has passed since last update.

sh、python などに実行させたいコマンド(文字列)を指定するオプション -c、 -e

Last updated at Posted at 2018-11-09

こんにちは。
sh, python などに、動かしたいコマンド(文字列)を指定して実行させる場合、指定する際のオプションは、-c-e、無しがあるようです(下記例)。

$ sh -c 'command'
$ python -c 'command'
$
$ perl -e 'command'
$ ruby -e 'command'
$ osascript -e 'command'
$
$ awk 'command'
$ jq 'command'
  • ワンライナーで多用しますが、-c-e を取違いしやすいのですが、そもそもなぜ複数種あるのか不思議に思っています。

なお上記例では、コマンド(文字列)をシングルクウォートで括っていますが('command')、シェルによって外されます1

$ echo 'command'
command

  1. シングルクウォートで括ると、シェルが文字通りに解釈してくれます。ただし、シングルクウォート文字を使うことはできませんので、その場合は、ダブルクウォートで括る必要があります。 

0
0
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
0