[UNIX CLI] Command Line(3)
1 minute read
UNIX COMMAND LINE
- UNIX CLI 정리(3)
echo
를 통해 variable의 name, value을 print할 수 있음
=
를 통해 shell variable 생성 가능
for [variable] in [list] ; do [body] ; done
를 통해 for loop 실행
echo
- variable의 value를 print할 시
$
를 앞에 붙여줘야 함
- 대표적인 variable
- OSTYPE : User’s OS type
- HOME : User’s home directory
- PWD : User’s present working directory
- SHELL : Current shell program
- USER : User’s ID
echo USER # USER
echo $USER # jisu
=
=
앞,뒤에 공백이 있으면 안됨
- assign된 변수를 호출할 때는
$
를 사용해야 함
# assign iris.cvs as example
example=iris.csv
# print the first line of example(iris.csv)
head -n 1 $example
=
=
앞,뒤에 공백이 있으면 안됨
- assign된 변수를 호출할 때는
$
를 사용해야 함
# assign iris.cvs as example
example=iris.csv
# print the first line of example(iris.csv)
head -n 1 $example
for
for [variable] in [list] ; do [body] ; done
# print all the filename in pwd
for filename in *; do echo $filename; done
# print the last row of rows including 2017-07 from all the files in directory seasonal
for f in seasonal/*.csv; do grep 2017-07 $f | tail -n 1; done
# print all the file names and the second row in directory seasonal
for f in seasonal/*.csv; do echo $f; head -n 2 $f | tail -n 1; done