5日目まとめ-シェル、入力、出力
前提
bash-3.2$ ls
AAA
通常のコマンド実行
bash-3.2$ cat AAA BBB
hoge
cat: BBB: No such file or directory
リダイレクト
bash-3.2$ cat AAA BBB > out.txt
cat: BBB: No such file or directory
bash-3.2$ cat out.txt
hoge
リダイレクト2
bash-3.2$ cat AAA BBB 2> error.txt
hoge
bash-3.2$ cat error.txt
cat: BBB: No such file or directory
パイプ
bash-3.2$ cat AAA BBB|cat
cat: BBB: No such file or directory
hoge
シェルスクリプトと環境変数、シェル変数
環境変数
bash-3.2$ printenv|nl
1 TERM_PROGRAM=Apple_Terminal
(省略)
18 OLDPWD=/Users/nekonisi
bash-3.2$ env|nl
1 TERM_PROGRAM=Apple_Terminal
(省略)
18 OLDPWD=/Users/nekonisi
シェル変数+環境変数
bash-3.2$ set|nl
1 BASH=/bin/bash
(省略)
48 _=
子プロセスへの引き継ぎ
bash-3.2$ hoge="test"
bash-3.2$ export fuga="test2"
bash-3.2$ echo $hoge
test
bash-3.2$ echo $fuga
test2
bash-3.2$ bash
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2$ echo $hoge
bash-3.2$ echo $fuga
test2
シェルスクリプトのシェル変数の引き継ぎ
bash-3.2$ cat test.sh
# !/bin/bash
echo $hoge
bash-3.2$ hoge='hogeeee'
bash-3.2$ bash test.sh
bash-3.2$ source test.sh
hogeeee
bash-3.2$ ./test.sh
bash: ./test.sh: Permission denied
bash-3.2$ chmod +x test.sh
bash-3.2$ ./test.sh
bash-3.2$ echo $?
0