Linux-centos/Linux-centos__works

shell, bash

말하는감자 2019. 7. 10. 13:40

[Shell] 

OS의 커널 <-> 사용자 사이의 명령어 해석 및 처리 결과를 리턴해주는 시스템 프로그램(명령어 처리기) 
shell 환경으로 접속하는 보안접속 프로그램(SSH)를 일컫는 말 


1. history

최초의 shell은 bourne shell 
bourne shell을 개선한 본 어게인 셸(bash), C셸(csh), 콘셸(zsh), z셸(zsh)이 만들어짐 

최초의 셸은 속도가 빨랐지만 사용이 불편했기 때문에 사용자 친화적으로 나온것이 bash 
자유소프트웨어재단(리처드 스톨먼, 오픈 소스를 거부하며 소프트웨어와 소스코드가 무료로 배포되어야 한다는 입장)에서 개발 
리눅스 시스템의 기본 셸 
윈도우10에서도 사용 가능 


2. shell script

텍스트 형식으로 저장되는 프로그램 
한줄씩 순차적으로 읽어서 실행(스크립트) 
shell을 이용해서 컴퓨터에 입력할 명령을 텍스트로 작성하는 것 


3. Bash(Bourne again shell)

쉘의 한 종류 


4. 사용

쉘의 내부 명령어라면 스스로 실행한 뒤 화면에 표시 
내부 명령어가 아니라면 [PATH 환경변수]에 지정된 경로에서 입력받은 명령과 같은 파일을 찾아 [exec() 시스템콜]을 호출하여 실행 


1)

Login

Non Login

Login
  ID와 PASS를 입력해서 shell을 실행하는 것
  SSH 접속, 로컬에서 GUI를 통해서 실행
  .profile, .bash_profile 두 파일은 Login 할 때 로드되는 파일
  
  .profile
      부팅 후에 적용
      
  .bash_profile
      개인이 로그인 시에 적용
                
Non Login
  로그인 없이 실행
  ssh로 접속 후에 다시 bash를 실행하는 경우나(sh 파일이름.sh)
  GUI 세션에서 터미널을 띄우는 것


2)

.bashrc

.bash_profile

.profile

.bashrc - Non Login
  이미 로그인 한 상태에서 새 터미널 창을 열 때마다 로드
  예제)
  1. 로그인
  2. .bashrc 수정
  3. sh .bashrc
  4. 터미널창 새로 열기
  5. 로드
  
bash_profile - Login
  시스템에 로그인 할 때마다 로드 
  예제)
  1. /home/test/.bash_profile 안에 path 추가
  2. test 접속 종료
  3. test 이 접속 전까지 해당 사항은 적용되지 않음

profile - Login
  부팅 후에 자동 로드
  수정후에는 sh 로 로드 한 후에 재로그인시 로드
  예제)
  1. 부팅
  2. 기존의 설정 파일 로드
  3. /etc/profile 안에 path 추가
  4. sh profile
  5. 재로그인
  6. 로드


3) 권장 사항

환경 설정은 - profile 
alais, 함수 - bashrc 


4) 시스템에서 파일들의 실행 순서

/etc/profile.d/안에존재하는.sh -> /etc/profile -> /etc/bashrc -> ~/.bashrc -> ~/.bash_profile 


5) 시스템에서 파일들의 호출 순서

/etc/profile -> /etc/profile.d/안에존재하는.sh -> ~/.bash_profile -> ~/.bashrc -> /etc/bashrc 


6) 일하면서 볼 수 있는 파일들(logout, history 제외)

/etc/profile : 공통 
/etc/bashrc : 공통 
~/.bash_profile : 내꺼 
~/.bashrc : 내꺼 
/root/.bashrc : root꺼 
/root/.bash_profile : root꺼 


7) /etc/profile.d/안에 잇는 파일 리스트

256term.csh
bash_completion.sh
colorgrep.sh
colorls.sh
lang.csh
less.csh
sh.local
vim.sh
which2.sh 
256term.sh
colorgrep.csh
colorls.csh
csh.local
lang.sh
less.sh
vim.csh
which2.csh 




8)

~/.bash_profile

if [ -f ~/.bashrc ]; then 
        . ~/.bashrc 
fi
개인의 설정파일 중에 .bashrc 가 있다면 새 창을 열 때마다 로드하도록 설정이 기본적으로 잡혀있습니다 



9)

/etc/profile

/etc/bashrc

for i in /etc/profile.d/*.sh ; do 
    if [ -r "$i" ]; then 
        if [ "$PS1" ]; then 
            . $i 
        else 
            . $i >/dev/null 2>&1 
        fi 
    fi 
done
/etc/profile.d/안에존재하는.sh 를 실행 








'Linux-centos > Linux-centos__works' 카테고리의 다른 글

disk free, disk use  (0) 2019.07.10
hard link, soft link, inode  (0) 2019.07.10
파일 바로 읽기  (0) 2019.07.09
다른 서버로 파일 복사하기  (0) 2019.07.09
가상단말  (0) 2019.07.09