Linux/shell script3 [Linux] shell script for문 정리 shell script for문이란 ? 프로그램 언어에서 사용하는 for이랑 같은 반복문을 뜻합니다. 리스트나 배열과 같이 다수의 값을 이용하여 동일한 작업을 처리할 때 사용합니다. 또한 c언어 기반으로 만들어진 shell의 for문 같은 경우 다른 언어와 다르게 단순한 파일구조를 가지고 있습니다. for문 구조 for [expression] in [range] do [repetition] done for문 특징 1. 보통 in 앞에는 변수 뒤에는 범위를 나타냅니다. 2. 변수를 입력할 때는 $를 붙입니다. 3. for문을 사용할 때는 do로 시작하고 스크립트가 끝날 때는 done으로 끝냅니다. 4. in을 붙이는 건 선택사항입니다. (python 프로그래밍에는 for문에서 do와 done을 사용을 안해.. 2022. 6. 12. [Linux] shell script if문 정리 shell script if문이란 ? 프로그램 언어에서 사용하는 if랑 같은 조건문을 뜻합니다. 조건이 참인지 거짓인지 판단한 후 사용자가 입력한 스크립트를 수행시켜줍니다. 또한 c언어 기반으로 만들어진 shell의 if문 같은 경우 다른 언어와 다르게 단순한 파일구조를 가지고 있습니다. if문 구조 if [ expression ]; then command elif [ expression ]; then command else fi if문 특징 1. [ ] (대괄호)를 사용할 때는 문장 앞에 공백이 있어야 합니다. 2. 변수를 입력할 때는 $를 붙입니다. 3. if로 시작하고 스크립트를 끝낼 때는 fi로 끝냅니다. (python 프로그래밍에는 if문을 사용시 fi로 안 닫아도 error가 출력되지 않습니다.. 2022. 6. 11. [Linux] sed명령어를 이용해서 shell script로 password 변경하는 법 cent 환경으로 password 변경하는 법 sed -i "s|#PasswordAuthentication no|PasswordAuthentication yes|g" /etc/ssh/sshd_config systemctl restart sshd echo '' | passwd --stdin ec2-user ubuntu 환경으로 password 변경하는 법 sed -i "s/PasswordAuthentication no/PasswordAuthentication yes/g" /etc/ssh/sshd_config systemctl restart sshd echo '' | chpasswd 2022. 4. 4. 이전 1 다음