일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 정보처리기사
- 사용자100명
- 환경정보
- 사양
- 스마트시티
- 일본대학원
- DevNet
- 명령어
- 코로나바이러스
- 부자아빠가난한아빠
- JMeter
- certification
- move앱
- 스펙정보
- 5G
- 韓国ヒップホップ
- 일본유학
- 사양정보
- 성능측정
- 다음메일
- gbd-200
- ads.txt
- 동시접속
- 200-301
- 4차산업
- QA
- ios
- 韓国
- 리눅스
- 한국판뉴딜
- Today
- Total
IT 컴퓨터공학 자료실
리눅스 배쉬 셀, 스크립트 강의 2 - 링크드인, Kevin Dankwardt 본문
※Title : Sourcing and aliasing with bash
* Source Scripts
- source example.sh, or . example.sh
- It is "dot space" as a short way to source a script.
- The shell executed the script in the shell's own process instead of in a new process.
- Sourceing is a common way to import variable assignments or functions.
- the sourced script is executed within the calling shell's process.
* Working with Aliases
- The alias command allows for short command alternatives: alias ll="ls -l".
- Some people use an alias to give an alias to give an alternative, more familiar name or to fix common typo to a Linux command.
- alias copy=cp
- alias rn=mv
- alias mroe=more
mroe myfile
ls -l | mroe
- List defined aliases by simply typing alias
- Unset an alias with the unalias command
명령어 실습)
cat setx.sh
chmod +x setx.sh
echo $x
./setx.sh
echo $x
source ./setx.sh
echo $x
x=1
echo $x
. ./setx.sh
echo $x
ls -l /usr/bin | more
ls -l /usr/bin | mroe
alias ls
unalias ls
=======================================
※Title : Displaying text with the echo command
*Using the Echo Command
- Built into Bash and doesn't start a new process
-n => don't print a trailing newline
-e => enable backslash escaped characters like \n and \t
-E => disable backslash escaped characters in case they were enabled by default
- ls * would list contents of directories:
echo * would show file and directory names
- Use file redirection techniques to send the output to other files, such stderr:
echo 'Warning Will Robinson!' >&2
명령어 실습 )
cat echoes.sh
./echoes.sh
=======================================
※Title : Challenges : Scripts with exported variables, sourcing, and echo
- Write a Bash script, with the "shebang" inside, that prints the variable A
- Run your script without defining or setting a variable A in your shell
- Run it again after setting A=1 on the command line before you run the script
- Finally run it after doing : export A = 2 on the command line
* Challenge: Source
- Write a script, set.sh, that sets A=10
- On the command line set A=5, and then run your script that prints A to see it print A. A should be exported.
- On the command line set A=5. In your script that prints A, before printing A, source set.sh. You should see the script now print A is 10.
- On the command line set A=5. In your script that prints A, run Set.sh; don't source it. You should see that the script prints A=5.
* Challenge: Echo
- Write a script that echoes the line
"Hello, World\n\n"
- Add the -n option to the echo and run again
- Replace the -n with -e and run again
- what do they print? How does their output differ?
=======================================
※Title : Challenge : Solutions : Scripts with exported variables, sourcing, and echo
- what do they print? How does their output differ?
정답 )
cat prA.sh
unset A
./prA.sh
A=1
./prA.sh
export A=2
./prA.sh
cat set.sh
export A
A=5
./set.sh
echo $A
cat prA2.sh
./prA2.sh
echo $A
A=5
echo $A
./set.sh
echo $A
cat prA3.sh
echo $A
./prA3.sh
=======================
cat world.sh
./world.sh
cat world2.sh
./world2.sh
cat world3.sh
./world3.sh
=======================================
※Title : Challenge : Solutions : Scripts with exported variables, sourcing, and echo
'네트워크 > 리눅스' 카테고리의 다른 글
[리눅스] 기본 간단 쉘프로그래밍 소개 - 출처 OmeGa (0) | 2021.10.25 |
---|---|
리눅스 배쉬 셀, 스크립트 강의 1 - 링크드인, Kevin Dankwardt (0) | 2021.10.25 |
#!(Shebang, 셔뱅) 알고 쓰자! - 출처 : 금소니의 삶 (2) | 2021.10.21 |
Learning Linux Command Line - LinkedIn Learning, Scott Simpson Sammary (리눅스 커맨드 라인 강의 요약) (0) | 2021.10.07 |
SCP를 사용한 서버간 파일 전송 및 수신 - 출처 : ithub (0) | 2021.10.07 |