LoginSignup
1
1

More than 3 years have passed since last update.

シェルスクリプト コマンド

Last updated at Posted at 2019-11-17

単純コマンドまたは複合コマンドのことを”コマンド”と呼ぶ。

単純コマンド

コマンド名と引数を並べたもの

simple.sh
# 内部コマンド(OSやシェルに組み込まれているコマンド)
# 組み込まれているため、コマンドの実体はない
# 一般的に使用頻度が高く、サイズが小さい
cd directory1
echo 'Hello!'

# help コマンドで出力されるのが組み込みコマンド
$ help
....
 alias [-p] [name[=value] ... ]                                            logout [n]
 bg [job_spec ...]                                                         mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C >
 bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keys>  popd [-n] [+N | -N]
....

# 外部コマンド(OSやシェルに組み込まれていないコマンド)
# 一般的に /usr/sbin や /usr/bin に存在する
# 一般的に使用頻度が低く、サイズが大きい
ls -alt
cp file1 file2

複合コマンド

if, case, for, while, シェル関数, グループコマンド, サブシェル

composite.sh
for n in {1..5}
do
  echo "Hello ${n}"
done

type コマンド

type コマンドでそのコマンドの存在を確認できる

type
$ type echo
echo is a shell builtin # 内部コマンド

$ type type
type is a shell builtin # 内部コマンド

$ type dummy
bash: type: dummy: not found # 存在しないコマンド

$ type ls
ls is aliased to `ls --color=auto' # 外部コマンド
1
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
1
1