<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://lycos7560.com/</link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Wed, 20 May 2026 21:06:25 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>어제와 내일의 나 그 사이의 이야기</title>
	<link>https://lycos7560.com/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>POSIX Shell: 낙서장</title>
		<link>https://lycos7560.com/etc/posix-shell-%eb%82%99%ec%84%9c%ec%9e%a5/40652/</link>
					<comments>https://lycos7560.com/etc/posix-shell-%eb%82%99%ec%84%9c%ec%9e%a5/40652/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 20 May 2026 20:29:01 +0000</pubDate>
				<category><![CDATA[개인 공부 저장용]]></category>
		<category><![CDATA[기타]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40652</guid>

					<description><![CDATA[<p>The post <a href="https://lycos7560.com/etc/posix-shell-%eb%82%99%ec%84%9c%ec%9e%a5/40652/">POSIX Shell: 낙서장</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh
language="Korean English Japanese"

print_languages() {
    for lang in $language; do
        printf "언어: %s\n" "$lang"
    done
}

print_languages2() {
    printf "언어: %s\n" "$1"
}

echo "-------------------"
print_languages
echo "-------------------"
for lang in $language; do
    print_languages2 "$lang"
done
echo "-------------------"


$ sh 00_Test.sh
-------------------
언어: Korean
언어: English
언어: Japanese
-------------------
언어: Korean
언어: English
언어: Japanese
-------------------</pre>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://lycos7560.com/etc/posix-shell-%eb%82%99%ec%84%9c%ec%9e%a5/40652/">POSIX Shell: 낙서장</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/etc/posix-shell-%eb%82%99%ec%84%9c%ec%9e%a5/40652/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>POSIX Shell: 환경변수(Environment Variable)</title>
		<link>https://lycos7560.com/etc/posix-shell-%ed%99%98%ea%b2%bd%eb%b3%80%ec%88%98environment-variable/40632/</link>
					<comments>https://lycos7560.com/etc/posix-shell-%ed%99%98%ea%b2%bd%eb%b3%80%ec%88%98environment-variable/40632/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 12 May 2026 22:15:59 +0000</pubDate>
				<category><![CDATA[개인 공부 저장용]]></category>
		<category><![CDATA[기타]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40632</guid>

					<description><![CDATA[<p>환경변수는 시스템의 설정값이나 실행 경로 등, 운영체제 전반에 걸쳐 공유되어야 하는 정보를 담고 있습니다. 일반 변수 vs 환경 변수 가장 큰 차이점은 &#8216;전파(Inheritance)&#8217;입니다. export 명령어: 환경변수 만들기 일반 변수를 환경변수로 승격시킬 때 export를 사용합니다. 주요 표준 환경변수 POSIX 시스템(Linux, AIX 등)에서 미리 정의되어 자주 쓰이는 변수들입니다. 변수명 설명 $PATH 명령어를 찾을 디렉토리 경로 목록 (콜론 [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/etc/posix-shell-%ed%99%98%ea%b2%bd%eb%b3%80%ec%88%98environment-variable/40632/">POSIX Shell: 환경변수(Environment Variable)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-59c788c2      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#일반-변수-vs-환경-변수" class="uagb-toc-link__trigger">일반 변수 vs 환경 변수</a><li class="uagb-toc__list"><a href="#export-명령어-환경변수-만들기" class="uagb-toc-link__trigger">export 명령어: 환경변수 만들기</a><li class="uagb-toc__list"><a href="#주요-표준-환경변수" class="uagb-toc-link__trigger">주요 표준 환경변수</a><li class="uagb-toc__list"><a href="#실전-예제-path-변수-조작하기" class="uagb-toc-link__trigger">실전 예제: PATH 변수 조작하기</a><li class="uagb-toc__list"><a href="#환경변수-확인법" class="uagb-toc-link__trigger">환경변수 확인법</a><li class="uagb-toc__list"><a href="#주의사항-변수의-수명" class="uagb-toc-link__trigger">주의사항: 변수의 수명</a><li class="uagb-toc__list"><a href="#환경에-따른-분기-case문-결합" class="uagb-toc-link__trigger">환경에 따른 분기 (case문 결합)</a><li class="uagb-toc__list"><a href="#자식에서-export로-변경하면-부모도-영향을-받나" class="uagb-toc-link__trigger">자식에서 export로 변경하면 부모도 영향을 받나?</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#왜-부모는-영향을-받지-않나" class="uagb-toc-link__trigger">왜 부모는 영향을 받지 않나?</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#예시-코드로-확인하기" class="uagb-toc-link__trigger">예시 코드로 확인하기</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#자식이-부모의-환경을-바꾸고-싶을-땐" class="uagb-toc-link__trigger">자식이 부모의 환경을 바꾸고 싶을 땐?</a></ul></ol>					</div>
									</div>
				</div>
			


<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">환경변수는 시스템의 설정값이나 실행 경로 등, 운영체제 전반에 걸쳐 공유되어야 하는 정보를 담고 있습니다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">일반 변수 vs 환경 변수</h2>



<p class="wp-block-paragraph">가장 큰 차이점은 &#8216;전파(Inheritance)&#8217;입니다.</p>



<ul class="wp-block-list">
<li><strong>일반 변수 (Local Variable):</strong> 현재 실행 중인 스크립트 내에서만 유효합니다.</li>



<li><strong>환경 변수 (Environment Variable):</strong> <code>export</code> 명령어를 통해 시스템의 &#8216;환경&#8217;으로 등록되어, 해당 쉘에서 실행하는 다른 스크립트나 프로그램에서도 읽을 수 있습니다.</li>
</ul>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">export 명령어: 환경변수 만들기</h2>



<p class="wp-block-paragraph">일반 변수를 환경변수로 승격시킬 때 <code>export</code>를 사용합니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># 1. 선언과 동시에 export (가장 많이 쓰임)
export MY_APP_HOME="/usr/local/engcross"

# 2. 이미 있는 변수를 export
VERSION="2.1.0"
export VERSION</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">주요 표준 환경변수</h2>



<p class="wp-block-paragraph">POSIX 시스템(Linux, AIX 등)에서 미리 정의되어 자주 쓰이는 변수들입니다.</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><td><strong>변수명</strong></td><td><strong>설명</strong></td></tr></thead><tbody><tr><td><strong><code>$PATH</code></strong></td><td>명령어를 찾을 디렉토리 경로 목록 (콜론 <code>:</code>으로 구분)</td></tr><tr><td><strong><code>$HOME</code></strong></td><td>현재 사용자의 홈 디렉토리 경로</td></tr><tr><td><strong><code>$USER</code></strong></td><td>현재 접속한 사용자 이름</td></tr><tr><td><strong><code>$PWD</code></strong></td><td>현재 작업 디렉토리 (Print Working Directory)</td></tr><tr><td><strong><code>$LANG</code></strong></td><td>시스템 언어 및 인코딩 (예: <code>ko_KR.UTF-8</code>)</td></tr><tr><td><strong><code>$SHELL</code></strong></td><td>현재 사용 중인 쉘의 경로</td></tr></tbody></table></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">실전 예제: PATH 변수 조작하기</h2>



<p class="wp-block-paragraph">내가 만든 스크립트를 어디서든 파일명만 입력해서 실행하고 싶을 때 <code>$PATH</code>를 수정합니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh

# 현재 PATH 끝에 내 스크립트 폴더 추가
export PATH="$PATH:/home/lycos7560/bin"

# 이제 /home/lycos7560/bin 안에 있는 파일들은 
# 절대 경로 없이 이름만으로 실행 가능합니다.</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">환경변수 확인법</h2>



<ul class="wp-block-list">
<li><code>env</code>: 현재 설정된 모든 환경변수 목록 출력</li>



<li><code>printenv PATH</code>: 특정 환경변수(<code>PATH</code>)의 값만 출력</li>



<li><code>set</code>: 환경변수뿐만 아니라 일반 변수, 함수까지 모두 포함해서 출력</li>
</ul>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">주의사항: 변수의 수명</h2>



<p class="wp-block-paragraph">스크립트 내부에서 <code>export</code>한 변수는 <strong>그 스크립트가 종료되면 사라집니다.</strong></p>



<ul class="wp-block-list">
<li><strong>부모 쉘(터미널)에 적용하고 싶다면?</strong></li>
</ul>



<p class="wp-block-paragraph">스크립트를 실행할 때 <code>./script.sh</code>가 아닌 <code>source ./script.sh</code> 또는 <code>. ./script.sh</code>를 사용해야 합니다. (이를 <strong>Sourcing</strong>이라고 합니다.)</p>



<ul class="wp-block-list">
<li><strong>영구히 적용하고 싶다면?</strong></li>
</ul>



<p class="wp-block-paragraph">사용자의 홈 디렉토리에 있는 <code>.profile</code> (또는 <code>.bash_profile</code>) 파일에 <code>export</code> 구문을 적어두어야 로그인할 때마다 로드됩니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">## parent.sh
#!/bin/sh
VAR1="Local"      # 일반 변수
export VAR2="Env" # 환경 변수

./child.sh        # 자식 프로세스 실행

## child.sh
#!/bin/sh
printf "VAR1: %s\n" "$VAR1" # 아무것도 안 나옴 (상속 안 됨)
printf "VAR2: %s\n" "$VAR2" # "Env" 출력 (상속 됨)

[결과]
$ ./parent.sh
VAR1: 
VAR2: Env

추가적으로 중요한 점은 자식이 가방(환경변수) 속 내용을 수정하거나 새 물건을 넣어도, 그 결과가 부모에게 돌아오지 않는다는 것입니다. 
자식이 종료되면 자식이 가졌던 가방 복사본은 그대로 파기되기 때문입니다.</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">환경에 따른 분기 (case문 결합)</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh

# 실행 환경(USER)에 따라 다른 설정 적용
case "$USER" in
    root)
        export LOG_LEVEL="DEBUG"
        export APP_PATH="/opt/app"
        ;;
    lycos7560)
        export LOG_LEVEL="INFO"
        export APP_PATH="/home/lycos7560/app"
        ;;
    *)
        printf "허용되지 않은 사용자입니다.\n"
        exit 1
        ;;
esac

printf "사용자: %s, 로그레벨: %s\n" "$USER" "$LOG_LEVEL"</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">환경변수는 스크립트가 외부 세계와 소통하는 통로입니다. </p>



<p class="wp-block-paragraph"><code>export</code>를 통해 내가 만든 설정값을 하위 프로그램에 전달하고, <code>$PATH</code>나 <code>$USER</code> 같은 시스템 변수를 이용해 상황에 맞는 유연한 스크립트를 작성해 보세요!</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">자식에서 export로 변경하면 부모도 영향을 받나?</h2>



<p class="wp-block-paragraph"><strong>아니요. 부모는 전혀 영향을 받지 않습니다.</strong></p>



<p class="wp-block-paragraph">이것은 쉘 스크립트 시스템의 아주 중요한 철칙인 <strong>&#8216;일방통행 상속&#8217;</strong> 때문입니다.</p>



<h3 class="wp-block-heading">왜 부모는 영향을 받지 않나?</h3>



<p class="wp-block-paragraph">부모가 자식 프로세스를 만들 때, 부모의 환경변수를 그대로 주는 게 아니라 &#8216;복사본&#8217;을 복사해서 넘겨주기 때문입니다.</p>



<p class="wp-block-paragraph">자식이 자기 손에 든 복사본 가방 안의 내용을 아무리 고치고 <code>export</code>를 다시 해도, 그것은 <strong>자신의 가방(자식 프로세스의 메모리)</strong> 내에서의 일일 뿐입니다. </p>



<p class="wp-block-paragraph">부모의 가방(부모 프로세스의 메모리)은 멀리 떨어져서 보호받고 있습니다.</p>



<h3 class="wp-block-heading">예시 코드로 확인하기</h3>



<p class="wp-block-paragraph">child.sh</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh
export MY_VAL="Changed by Child"
printf "자식: 값을 변경했습니다 -> %s\n" "$MY_VAL"</pre>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">parent.sh</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh
export MY_VAL="Original Parent Value"

printf "부모: 실행 전 값 -> %s\n" "$MY_VAL"

# 자식 스크립트 실행
./child.sh

printf "부모: 자식 종료 후 값 -> %s\n" "$MY_VAL"</pre>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">실행 결과:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">부모: 실행 전 값 -> Original Parent Value
자식: 값을 변경했습니다 -> Changed by Child
부모: 자식 종료 후 값 -> Original Parent Value</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">자식이 부모의 환경을 바꾸고 싶을 땐?</h3>



<p class="wp-block-paragraph">자식 프로세스를 &#8216;별도로&#8217; 띄우지 않고, <strong>부모의 몸 안에서 직접 실행</strong>하게 하면 됩니다. </p>



<p class="wp-block-paragraph">이것을 <strong>Sourcing(소싱</strong>)이라고 합니다.</p>



<ul class="wp-block-list">
<li><strong>일반 실행 (<code>./child.sh</code>):</strong> 새로운 자식 쉘을 생성 (부모 영향 X)</li>



<li><strong>소싱 실행 (<code>. ./child.sh</code>):</strong> 현재 부모 쉘에서 코드를 그대로 읽어서 실행 (부모 영향 O)</li>
</ul>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">이 개념은 보안과 안정성을 위한 개념입니다.</p>



<p class="wp-block-paragraph">자식 프로그램이 멋대로 부모 시스템의 설정을 변경하면 문제가 되기 때문이죠.</p>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://lycos7560.com/etc/posix-shell-%ed%99%98%ea%b2%bd%eb%b3%80%ec%88%98environment-variable/40632/">POSIX Shell: 환경변수(Environment Variable)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/etc/posix-shell-%ed%99%98%ea%b2%bd%eb%b3%80%ec%88%98environment-variable/40632/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>POSIX Shell: case 문</title>
		<link>https://lycos7560.com/etc/posix-shell-case-%eb%ac%b8/40629/</link>
					<comments>https://lycos7560.com/etc/posix-shell-case-%eb%ac%b8/40629/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 12 May 2026 22:07:50 +0000</pubDate>
				<category><![CDATA[개인 공부 저장용]]></category>
		<category><![CDATA[기타]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40629</guid>

					<description><![CDATA[<p>if 문이 &#8220;예/아니오&#8221;라는 논리적 판단에 강하다면, case 문은 &#8220;이 값은 어디에 해당하나?&#8221;라는 패턴 매칭에 최적화되어 있습니다. 코드의 가독성을 높여주는 case 문의 모든 것을 알아봅니다. 기본 구조 case 문은 변수의 값을 여러 패턴과 비교하며, 처음으로 일치하는 블록을 실행합니다. 활용 가능한 패턴 종류 POSIX 표준에서 지원하는 패턴들입니다. 정규표현식과는 조금 다르니 주의하세요! 예제 ① 스크립트 인자(Argument) 처리 : [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/etc/posix-shell-case-%eb%ac%b8/40629/">POSIX Shell: case 문</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-66d4106a      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#기본-구조" class="uagb-toc-link__trigger">기본 구조</a><li class="uagb-toc__list"><a href="#활용-가능한-패턴-종류" class="uagb-toc-link__trigger">활용 가능한 패턴 종류</a><li class="uagb-toc__list"><a href="#예제" class="uagb-toc-link__trigger">예제</a><li class="uagb-toc__list"><a href="#사용자-입력yn-대소문자-무시하기" class="uagb-toc-link__trigger">사용자 입력(y/n) 대소문자 무시하기</a><li class="uagb-toc__list"><a href="#고급-bash-전용-기능-주의사항" class="uagb-toc-link__trigger">고급: Bash 전용 기능 주의사항</a><li class="uagb-toc__list"><a href="#if-vs-case-언제-무엇을-쓸까" class="uagb-toc-link__trigger">if vs case: 언제 무엇을 쓸까?</a></ol>					</div>
									</div>
				</div>
			


<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph"><code>if</code> 문이 &#8220;예/아니오&#8221;라는 논리적 판단에 강하다면, <strong><code>case</code> 문</strong>은 &#8220;이 값은 어디에 해당하나?&#8221;라는 <strong>패턴 매칭</strong>에 최적화되어 있습니다. </p>



<p class="wp-block-paragraph">코드의 가독성을 높여주는 <code>case</code> 문의 모든 것을 알아봅니다.</p>



<h2 class="wp-block-heading">기본 구조</h2>



<p class="wp-block-paragraph"><code>case</code> 문은 변수의 값을 여러 패턴과 비교하며, 처음으로 일치하는 블록을 실행합니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">case "$변수" in
    패턴1)
        명령어
        ;;  # 블록 종료 (C의 break와 유사)
    패턴2|패턴3)
        명령어  # | 로 OR 조건 표현 가능
        ;;
    *)
        명령어  # 일치하는 패턴이 없을 때 (else 역할)
        ;;
esac  # case를 거꾸로 쓴 것</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">활용 가능한 패턴 종류</h2>



<p class="wp-block-paragraph">POSIX 표준에서 지원하는 패턴들입니다. 정규표현식과는 조금 다르니 주의하세요!</p>



<ul class="wp-block-list">
<li><code>*</code>: 모든 문자열과 일치 (Default 처리용)</li>



<li><code>?</code>: 임의의 문자 <strong>딱 1개</strong>와 일치</li>



<li><code>[abc]</code>: a, b, c 중 하나와 일치</li>



<li><code>[a-z]</code>: 소문자 a부터 z 사이의 문자 하나와 일치</li>



<li><code>pat1|pat2</code>: 패턴1 또는 패턴2 중 하나와 일치 (<strong>OR 조건</strong>)</li>
</ul>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제</h2>



<p class="wp-block-paragraph">① 스크립트 인자(Argument) 처리 : 서비스 관리 스크립트(<code>start</code>, <code>stop</code> 등)를 만들 때 가장 많이 쓰이는 방식입니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh

ACTION="$1"

case "$ACTION" in
    start)
        printf "서비스를 시작합니다...\n"
        ;;
    stop)
        printf "서비스를 중지합니다...\n"
        ;;
    restart|reload)
        printf "재시작/설정 로드를 수행합니다...\n"
        ;;
    status)
        printf "현재 상태를 확인합니다...\n"
        ;;
    *)
        printf "사용법: %s {start|stop|restart|status}\n" "$0"
        exit 1
        ;;
esac</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">② 파일 확장자별 분기 처리 : <code>${FILE##*.}</code>와 조합하면 매우 강력해집니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh

FILE="backup.tar.gz"
EXT="${FILE##*.}"

case "$EXT" in
    gz|tgz)
        printf "Gzip 압축 파일입니다. 해제 명령: tar xzf %s\n" "$FILE"
        ;;
    zip)
        printf "Zip 파일입니다. 해제 명령: unzip %s\n" "$FILE"
        ;;
    log)
        printf "로그 파일입니다. 실시간 모니터링을 시작합니다.\n"
        ;;
    *)
        printf "지원하지 않는 파일 형식입니다: %s\n" "$EXT"
        ;;
esac</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">사용자 입력(y/n) 대소문자 무시하기</h2>



<p class="wp-block-paragraph">사용자로부터 <code>yes</code>, <code>Yes</code>, <code>YES</code> 등을 한 번에 입력받고 싶을 때 대괄호(<code>[]</code>) 패턴이 유용합니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh

printf "계속 진행하시겠습니까? [y/n]: "
read ANSWER

case "$ANSWER" in
    [yY]|[yY][eE][sS])
        printf "진행을 결정하셨습니다.\n"
        ;;
    [nN]|[nN][oO])
        printf "작업을 취소합니다.\n"
        exit 0
        ;;
    *)
        printf "잘못된 입력입니다. y 또는 n을 입력해 주세요.\n"
        exit 1
        ;;
esac</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">고급: Bash 전용 기능 주의사항</h2>



<p class="wp-block-paragraph">Bash 4.0 이상에서는 <code>;</code> 대신 <code>;&amp;</code> (fall-through)나 <code>;;&amp;</code> 등을 사용할 수 있지만, 이는 <strong>POSIX 표준이 아닙니다.</strong></p>



<ul class="wp-block-list">
<li><strong><code>; &amp;</code></strong>: 다음 패턴의 일치 여부와 상관없이 무조건 다음 블록을 실행합니다.</li>



<li><strong><code>;; &amp;</code></strong>: 다음 패턴들을 계속 검사하여 일치하는 것이 있다면 또 실행합니다.</li>
</ul>



<p class="wp-block-paragraph"><strong>POSIX 팁:</strong> 이식성이 중요한 스크립트에서는 오직 <code><strong>;;</strong></code>만 사용하세요. <code><strong>;</strong></code> 하나만 쓰거나 다른 기호를 섞으면 구형 쉘에서 에러가 납니다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">if vs case: 언제 무엇을 쓸까?</h2>



<ul class="wp-block-list">
<li><strong><code>if</code> 문이 유리할 때</strong>: 숫자 크기 비교(<code>-gt</code>, <code>-lt</code>), 복잡한 논리 조합(<code>&amp;&amp;</code>, <code>||</code>), 파일 존재 여부 확인 등.</li>



<li><strong><code>case</code> 문이 유리할 때</strong>: 하나의 변수 값이 특정 문자열 패턴 중 무엇인지 분류할 때 (3개 이상의 분기라면 <code>case</code>를 강력 추천).</li>
</ul>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph"><code>case</code> 문을 사용하면 스크립트가 훨씬 읽기 쉬워지고 구조가 명확해집니다. </p>



<p class="wp-block-paragraph">특히 인자 처리나 사용자 응답 처리에서 <code>case</code>를 활용해 보세요. 여러분의 코드가 한층 더 전문가답게 보일 것입니다!</p>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://lycos7560.com/etc/posix-shell-case-%eb%ac%b8/40629/">POSIX Shell: case 문</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/etc/posix-shell-case-%eb%ac%b8/40629/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>POSIX Shell: 변수(Variables) &#038; 문자열(String)</title>
		<link>https://lycos7560.com/etc/posix-shell-%eb%b3%80%ec%88%98variables-%eb%ac%b8%ec%9e%90%ec%97%b4string/40627/</link>
					<comments>https://lycos7560.com/etc/posix-shell-%eb%b3%80%ec%88%98variables-%eb%ac%b8%ec%9e%90%ec%97%b4string/40627/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 12 May 2026 21:50:52 +0000</pubDate>
				<category><![CDATA[개인 공부 저장용]]></category>
		<category><![CDATA[기타]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40627</guid>

					<description><![CDATA[<p>쉘 스크립트에서 변수는 별도의 선언(형식 지정) 없이 바로 사용할 수 있어 유연하지만, 그만큼 문법이 엄격한 부분도 있습니다. 특히 공백과 따옴표 사용법이 핵심입니다. 변수 선언과 사용 (Variables) Shell 변수는 선언 시 타입을 지정하지 않으며, 공백에 매우 민감합니다. 특수 변수 (Special Variables) 스크립트 실행 시 자동으로 할당되는 예약 변수들입니다. 변수 의미 예시 (./run.sh aix hacmp) $0 스크립트 [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/etc/posix-shell-%eb%b3%80%ec%88%98variables-%eb%ac%b8%ec%9e%90%ec%97%b4string/40627/">POSIX Shell: 변수(Variables) &amp; 문자열(String)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-dfed9df5      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#변수-선언과-사용-variables" class="uagb-toc-link__trigger">변수 선언과 사용 (Variables)</a><li class="uagb-toc__list"><a href="#특수-변수-special-variables" class="uagb-toc-link__trigger">특수 변수 (Special Variables)</a><li class="uagb-toc__list"><a href="#기본값-처리-default-values" class="uagb-toc-link__trigger">기본값 처리 (Default Values)</a><li class="uagb-toc__list"><a href="#패턴-제거-pattern-removal" class="uagb-toc-link__trigger">패턴 제거 (Pattern Removal)</a><li class="uagb-toc__list"><a href="#문자열-치환-및-대소문자-변환-bash-확장" class="uagb-toc-link__trigger">문자열 치환 및 대소문자 변환 (Bash 확장)</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#문자열-치환" class="uagb-toc-link__trigger">문자열 치환</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#대소문자-변환" class="uagb-toc-link__trigger">대소문자 변환</a></li></ul></li><li class="uagb-toc__list"><a href="#문자열-분리-ifs-활용" class="uagb-toc-link__trigger">문자열 분리 (IFS 활용)</a></ul></ol>					</div>
									</div>
				</div>
			


<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">쉘 스크립트에서 변수는 별도의 선언(형식 지정) 없이 바로 사용할 수 있어 유연하지만, 그만큼 문법이 엄격한 부분도 있습니다. </p>



<p class="wp-block-paragraph">특히 <strong>공백</strong>과 <strong>따옴표</strong> 사용법이 핵심입니다.</p>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">변수 선언과 사용 (Variables)</h2>



<p class="wp-block-paragraph">Shell 변수는 선언 시 타입을 지정하지 않으며, <strong>공백</strong>에 매우 민감합니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># 선언: = 앞뒤 공백 금지 (필수!)
NAME="lycos7560" 
COUNT=42 

# 사용: $ 또는 ${}를 사용
echo "$NAME"       # 일반적인 사용
echo "${NAME}"     # 경계를 명확히 할 때 권장
echo "User_${NAME}_log" # 변수명 뒤에 문자가 붙을 때 필수</pre>



<ul class="wp-block-list">
<li><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/26a0.png" alt="⚠" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 주의:</strong> <code>NAME = value</code>처럼 공백을 넣으면 시스템은 <code>NAME</code>을 변수가 아닌 <strong>명령어</strong>로 인식하여 에러(<code>command not found</code>)를 발생시킵니다</li>
</ul>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">특수 변수 (Special Variables)</h2>



<p class="wp-block-paragraph">스크립트 실행 시 자동으로 할당되는 예약 변수들입니다.</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><td><strong>변수</strong></td><td><strong>의미</strong></td><td><strong>예시 (./run.sh aix hacmp)</strong></td></tr></thead><tbody><tr><td><strong><code>$0</code></strong></td><td>스크립트 이름</td><td><code>./run.sh</code></td></tr><tr><td><strong><code>$1</code> ~ <code>$9</code></strong></td><td>위치 매개변수 (인자)</td><td><code>$1</code>은 <code>aix</code>, <code>$2</code>는 <code>hacmp</code></td></tr><tr><td><strong><code>$#</code></strong></td><td>인자 개수</td><td><code>2</code></td></tr><tr><td><strong><code>$@</code></strong></td><td>모든 인자 (각각 분리)</td><td><code>"aix" "hacmp"</code></td></tr><tr><td><strong><code>$?</code></strong></td><td>마지막 명령어 종료 코드</td><td><code>0</code>(성공) 또는 <code>1~255</code>(실패)</td></tr><tr><td><strong><code>$$</code></strong></td><td>현재 프로세스 PID</td><td><code>1234</code></td></tr></tbody></table></figure>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">기본값 처리 (Default Values)</h2>



<p class="wp-block-paragraph">변수가 비어있을 때를 대비한 방어적 코딩 기법입니다.</p>



<ul class="wp-block-list">
<li><strong><code>${VAR:-default}</code></strong>: <code>VAR</code>이 비어있으면 <code>default</code>를 사용 (변수 값은 유지)</li>



<li><strong><code>${VAR:=default}</code></strong>: <code>VAR</code>이 비어있으면 <code>default</code>를 <strong>변수에 대입</strong></li>



<li><strong><code>${VAR:?message}</code></strong>: <code>VAR</code>이 비어있으면 메시지 출력 후 <strong>스크립트 종료</strong></li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># 예시
HOST=""
printf "Connecting to %s...\n" "${HOST:-localhost}"  # localhost 출력</pre>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">패턴 제거 (Pattern Removal)</h2>



<p class="wp-block-paragraph">파일 경로에서 파일명만 추출하거나 확장자를 뗄 때 가장 많이 사용하는 강력한 기능입니다.</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><td><strong>문법</strong></td><td><strong>설명</strong></td><td><strong>기억법</strong></td></tr></thead><tbody><tr><td><strong><code>${VAR#패턴}</code></strong></td><td>앞에서부터 <strong>최단</strong> 일치 제거</td><td><code>#</code>은 키보드 왼쪽(앞), 하나는 짧게</td></tr><tr><td><strong><code>${VAR##패턴}</code></strong></td><td>앞에서부터 <strong>최장</strong> 일치 제거</td><td><code>##</code>은 길게</td></tr><tr><td><strong><code>${VAR%패턴}</code></strong></td><td>뒤에서부터 <strong>최단</strong> 일치 제거</td><td><code>%</code>는 키보드 오른쪽(뒤), 하나는 짧게</td></tr><tr><td><strong><code>${VAR%%패턴}</code></strong></td><td>뒤에서부터 <strong>최장</strong> 일치 제거</td><td><code>%%</code>는 길게</td></tr></tbody></table></figure>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">FILE="/var/log/syslog.tar.gz"

echo "${FILE##*/}"  # syslog.tar.gz (경로 제거)
echo "${FILE%.*}"   # /var/log/syslog.tar (최종 확장자 제거)
echo "${FILE%%.*}"  # /var/log/syslog (모든 확장자 제거)
echo "${FILE%/*}"   # /var/log (디렉토리만 추출)

[결과]
$ ./01_hello.sh start
syslog.tar.gz
/var/log/syslog.tar
/var/log/syslog
/var/log</pre>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문자열 치환 및 대소문자 변환 (Bash 확장)</h2>



<p class="wp-block-paragraph"><strong>주의:</strong> 아래 기능들은 <strong>Bash 4.0 이상</strong>에서 지원됩니다. </p>



<p class="wp-block-paragraph">구형 AIX의 <code>/bin/sh</code>에서는 작동하지 않을 수 있으니 환경을 확인하세요.</p>



<h3 class="wp-block-heading">문자열 치환</h3>



<ul class="wp-block-list">
<li><code>${STR/old/new}</code>: 첫 번째 일치 항목만 치환</li>



<li><code>${STR//old/new}</code>: 모든 일치 항목 치환</li>
</ul>



<h3 class="wp-block-heading">대소문자 변환</h3>



<ul class="wp-block-list">
<li><code>${STR^^}</code>: 전체 대문자</li>



<li><code>${STR,,}</code>: 전체 소문자</li>
</ul>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문자열 분리 (IFS 활용)</h2>



<p class="wp-block-paragraph"><code>IFS</code>(Internal Field Separator)는 쉘이 단어를 나누는 기준 문자입니다. </p>



<p class="wp-block-paragraph">이를 변경하여 CSV 형태의 데이터를 쉽게 분리할 수 있습니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># 콜론(:)으로 구분된 데이터 파싱
LINE="hostname:192.168.1.1:8080"
IFS=":" read -r HOST IP PORT &lt;&lt; EOF
$LINE
EOF

printf "Host: %s, IP: %s, Port: %s\n" "$HOST" "$IP" "$PORT"</pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">POSIX 표준 변수 처리(<code>${#}</code>, <code>${%}</code>)는 매우 빠르고 효율적입니다. </p>



<p class="wp-block-paragraph"><code>sed</code>나 <code>awk</code> 같은 외부 명령어를 호출하지 않고도 쉘 자체 기능만으로 문자열을 처리하는 습관을 들이면 스크립트의 성능이 비약적으로 향상됩니다!</p>



<p class="wp-block-paragraph"></p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">00_Test.sh

#!/bin/sh
echo "\$0  = $0      → 현재 스크립트의 이름"
echo "\$1  = $1      → 첫 번째 인자"
echo "\${10} = ${10}    → 열 번째 인자 (\$10 이상은 \${}로 감싸야 함)"
echo "\$#  = $#      → 전달된 인자의 개수"
echo "\$*  = $*      → 모든 인자 (하나의 문자열)"
echo "\$@  = $@      → 모든 인자 (각각 분리)"
echo "\$\$ = $$     → 현재 스크립트의 프로세스 ID"
echo "\$?  = $?      → 마지막 명령어 종료 상태 (0=성공)"
echo "\!  = $!      → 마지막 백그라운드 명령어의 PID"
echo "\$_  = $_     → 마지막 인자 또는 명령어"
echo "\$-  = $-      → 현재 셸 옵션"




$ sh 00_Test.sh 1 2 3 4 5 6 7 8 9 10 11 12
$0  = 00_Test.sh      → 현재 스크립트의 이름
$1  = 1      → 첫 번째 인자
${10} = 10    → 열 번째 인자 ($10 이상은 ${}로 감싸야 함)
$#  = 12      → 전달된 인자의 개수
$*  = 1 2 3 4 5 6 7 8 9 10 11 12      → 모든 인자 (하나의 문자열)
$@  = 1 2 3 4 5 6 7 8 9 10 11 12      → 모든 인자 (각각 분리)
$$ = 8455     → 현재 스크립트의 프로세스 ID
$?  = 0      → 마지막 명령어 종료 상태 (0=성공)
\!  =       → 마지막 백그라운드 명령어의 PID
$_  = \!  =       → 마지막 백그라운드 명령어의 PID     → 마지막 인자 또는 명령어





#!/bin/sh
# ./test.sh "AIX 6.1" "HACMP cluster" "node1"

echo "=== 인자 개수: $# ==="
echo ""

echo "--- \"\$*\" 사용 ---"
i=1
for arg in "$*"; do
    echo "  [$i] $arg"
    i=$((i+1))
done

echo ""
echo "--- \"\$@\" 사용 ---"
i=1
for arg in "$@"; do
    echo "  [$i] $arg"
    i=$((i+1))
done


$ sh 00_Test.sh 1 2 3 4 5 6 7 8 9 10 11
=== 인자 개수: 11 ===

--- "$*" 사용 ---
  [1] 1 2 3 4 5 6 7 8 9 10 11

--- "$@" 사용 ---
  [1] 1
  [2] 2
  [3] 3
  [4] 4
  [5] 5
  [6] 6
  [7] 7
  [8] 8
  [9] 9
  [10] 10
  [11] 11</pre>
<p>The post <a href="https://lycos7560.com/etc/posix-shell-%eb%b3%80%ec%88%98variables-%eb%ac%b8%ec%9e%90%ec%97%b4string/40627/">POSIX Shell: 변수(Variables) &amp; 문자열(String)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/etc/posix-shell-%eb%b3%80%ec%88%98variables-%eb%ac%b8%ec%9e%90%ec%97%b4string/40627/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>POSIX Shell: 표준 함수(Function)</title>
		<link>https://lycos7560.com/etc/posix-shell-%ed%91%9c%ec%a4%80-%ed%95%a8%ec%88%98function/40616/</link>
					<comments>https://lycos7560.com/etc/posix-shell-%ed%91%9c%ec%a4%80-%ed%95%a8%ec%88%98function/40616/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 12 May 2026 21:27:29 +0000</pubDate>
				<category><![CDATA[개인 공부 저장용]]></category>
		<category><![CDATA[기타]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40616</guid>

					<description><![CDATA[<p>스크립트의 규모가 커지면 중복되는 코드를 줄이기 위해 함수(Function)를 사용해야 합니다. POSIX 표준을 따르면서 어디서나 잘 작동하는 함수 작성법을 알아봅니다. 기본 문법 가장 중요한 차이점은 function이라는 키워드를 쓰지 않는다는 것입니다. 인자 전달 (Arguments) 함수로 값을 보낼 때는 별도의 파라미터 이름을 정의하지 않고, 스크립트 실행 인자와 똑같이 위치 매개변수($1, $2, &#8230;)를 사용합니다. 변수 의미 $1, $2 첫 [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/etc/posix-shell-%ed%91%9c%ec%a4%80-%ed%95%a8%ec%88%98function/40616/">POSIX Shell: 표준 함수(Function)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-19f9e4de      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#기본-문법" class="uagb-toc-link__trigger">기본 문법</a><li class="uagb-toc__list"><a href="#인자-전달-arguments" class="uagb-toc-link__trigger">인자 전달 (Arguments)</a><li class="uagb-toc__list"><a href="#지역-변수-local-variables-주의사항" class="uagb-toc-link__trigger">지역 변수 (Local Variables) 주의사항</a><li class="uagb-toc__list"><a href="#반환값-return-value" class="uagb-toc-link__trigger">반환값 (Return Value)</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#return-종료-상태-코드-반환" class="uagb-toc-link__trigger">① return: 종료 상태 코드 반환</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#printfecho-데이터-결과-반환" class="uagb-toc-link__trigger">② printf/echo: 데이터 결과 반환</a></li></ul></li><li class="uagb-toc__list"><a href="#로깅-함수-만들기" class="uagb-toc-link__trigger">로깅 함수 만들기</a><li class="uagb-toc__list"><a href="#핵심-요약-checklist" class="uagb-toc-link__trigger">핵심 요약 (Checklist)</a><li class="uagb-toc__list"><a href="#주의사항" class="uagb-toc-link__trigger">주의사항</a></ul></ol>					</div>
									</div>
				</div>
			


<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">스크립트의 규모가 커지면 중복되는 코드를 줄이기 위해 함수(Function)를 사용해야 합니다. </p>



<p class="wp-block-paragraph">POSIX 표준을 따르면서 어디서나 잘 작동하는 함수 작성법을 알아봅니다.</p>



<h2 class="wp-block-heading">기본 문법</h2>



<p class="wp-block-paragraph">가장 중요한 차이점은 <strong><code>function</code>이라는 키워드를 쓰지 않는다</strong>는 것입니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># POSIX 표준 방식 (권장 <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" />)
함수이름() {
    # 실행할 내용
}

# Bash 전용 방식 (POSIX에서는 지양 <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/274c.png" alt="❌" class="wp-smiley" style="height: 1em; max-height: 1em;" />)
# function 함수이름 { ... }</pre>



<ul class="wp-block-list">
<li><strong>함수 정의</strong>: 반드시 함수를 <strong>호출하기 전</strong>에 먼저 정의되어 있어야 합니다. (보통 스크립트 상단에 배치)</li>



<li><strong>호출</strong>: 함수 이름만 적으면 실행됩니다. (괄호 <code>()</code> 없이 이름만 사용)</li>
</ul>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">인자 전달 (Arguments)</h2>



<p class="wp-block-paragraph">함수로 값을 보낼 때는 별도의 파라미터 이름을 정의하지 않고, 스크립트 실행 인자와 똑같이 위치 매개변수(<code>$1</code>, <code>$2</code>, &#8230;)를 사용합니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">greet() {
    printf "안녕하세요, %s님!\n" "$1"
}

greet "홍길동"  # $1에 "홍길동"이 전달됨</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><td><strong>변수</strong></td><td><strong>의미</strong></td></tr></thead><tbody><tr><td><code>$1</code>, <code>$2</code></td><td>첫 번째, 두 번째 인자</td></tr><tr><td><code>$#</code></td><td>함수에 전달된 인자의 총 개수</td></tr><tr><td><code>$@</code></td><td>전달된 모든 인자 목록</td></tr></tbody></table></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">지역 변수 (Local Variables) 주의사항</h2>



<p class="wp-block-paragraph">이 부분이 POSIX 표준의 가장 큰 제약사항입니다.</p>



<ul class="wp-block-list">
<li><strong>Bash</strong>:</li>
</ul>



<p class="wp-block-paragraph"><code>local</code> 키워드를 사용하여 함수 내부에서만 쓰는 변수를 만들 수 있습니다.</p>



<ul class="wp-block-list">
<li><strong>POSIX (sh)</strong>: </li>
</ul>



<p class="wp-block-paragraph">표준에는 <strong><code>local</code> 키워드가 없습니다.</strong> </p>



<p class="wp-block-paragraph">함수 안에서 선언한 변수도 기본적으로 전역 변수(Global)가 되어 스크립트 전체에 영향을 줍니다.</p>



<p class="wp-block-paragraph"><strong>해결책:</strong> 함수 내에서만 쓰는 변수는 <code>_var_name</code>처럼 앞에 언더바를 붙이거나, 이름이 겹치지 않게 주의해서 지어야 합니다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">반환값 (Return Value)</h2>



<p class="wp-block-paragraph">함수의 실행 결과를 처리하는 방법은 두 가지입니다.</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><td><strong>구분</strong></td><td><strong>종료 상태 코드 (Exit Status)</strong></td><td><strong>표준 출력 (Standard Output)</strong></td></tr></thead><tbody><tr><td><strong>데이터 타입</strong></td><td>0 ~ 255 사이의 <strong>정수</strong></td><td><strong>문자열</strong> (텍스트 데이터)</td></tr><tr><td><strong>확인 방법</strong></td><td><code>$?</code> 변수로 확인</td><td><code>$(함수이름)</code> (명령어 치환)으로 캡처</td></tr><tr><td><strong>주 용도</strong></td><td>성공(0) 또는 실패(그 외) 판별</td><td>처리된 결과값 전달 (이름, 날짜 등)</td></tr><tr><td><strong>비유</strong></td><td>&#8220;내 일 잘 끝냈어!&#8221; (결과 보고서의 합격/불합격 도장)</td><td>&#8220;내가 만든 결과물이야.&#8221; (결과 보고서의 내용물)</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">① <code>return</code>: 종료 상태 코드 반환</h3>



<p class="wp-block-paragraph">숫자(0~255)만 반환할 수 있으며, 주로 성공(0)과 실패(그 외)를 알리는 용도입니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">is_file_exist() {
    if [ -f "$1" ]; then
        return 0 # 성공
    else
        return 1 # 실패
    fi
}</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">② <code>printf</code>/<code>echo</code>: 데이터 결과 반환</h3>



<p class="wp-block-paragraph">문자열이나 계산 결과 자체를 받아야 할 때는 출력문을 이용하고 명령어 치환(<code>$()</code>)으로 낚아챕니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">get_date() {
    printf "%s" "$(date +%Y-%m-%d)"
}

TODAY=$(get_date)
printf "오늘 날짜: %s\n" "$TODAY"</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">간단한 예시</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh

get_user_status() {
    _USER_NAME="TestUser1"  # 실제 사용자 이름을 여기에 설정
    
    if [ "$_USER_NAME" = "TestUser" ]; then
        # 1. 표준 출력으로 문자열을 내보냄 (반환 문자열)
        printf "Active User"
        # 2. 종료 코드로 성공을 알림 (명령어 마지막 실행 결과가 0)
        return 0
    else
        printf "Unknown"
        return 1
    fi
}

# 실행 및 데이터 캡처
STATUS_TEXT=$(get_user_status)  # "Active User"가 변수에 저장됨 , 출력 문자열($()): 함수가 무슨 데이터를 만들었는지 알려줌 (실제 값)
STATUS_CODE=$?                  # 0이 변수에 저장됨

printf "문자열 결과: %s\n" "$STATUS_TEXT"
printf "상태 코드: %d\n" "$STATUS_CODE"</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">로깅 함수 만들기</h2>



<p class="wp-block-paragraph">실제 프로젝트에서 유용하게 쓸 수 있는 메시지 출력 함수 예시입니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh

# 로깅 함수 정의
log_message() {
    _LEVEL="$1"
    _MSG="$2"
    _TIME=$(date '+%H:%M:%S')

    # 형식: [시간] [로그레벨] 메시지
    printf "[%s] [%s] %s\n" "$_TIME" "$_LEVEL" "$_MSG"
}

# 함수 호출
log_message "INFO" "애플리케이션을 시작합니다."
log_message "WARN" "설정 파일이 없습니다. 기본값을 사용합니다."


if [ "$?" -eq 0 ]; then                                  # 상태 코드($?): 마지막 함수가 어떻게 끝났는지 알려줌 (성공/실패)
    log_message "SUCCESS" "작업이 성공적으로 끝났습니다."
fi</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">핵심 요약 (Checklist)</h2>



<ul class="wp-block-list">
<li><strong><code>function</code> 키워드는 빼자</strong>: 그냥 <code>name() { ... }</code> 형식을 사용하세요.</li>



<li><strong><code>local</code>은 표준이 아니다</strong>: 변수 이름 충돌에 주의하세요.</li>



<li><strong>인자는 <code>$1</code>, <code>$2</code>로</strong>: 함수 호출 시 옆에 나열하면 됩니다.</li>



<li><strong>복잡한 결과는 <code>printf</code>로</strong>: 값을 돌려받고 싶을 땐 출력을 이용하세요.</li>
</ul>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">주의사항</h2>



<p class="wp-block-paragraph"> &#8220;출력되는 모든 것&#8221; : 함수 안에서 <code>printf</code>나 <code>echo</code>로 찍는 <strong>모든 내용</strong>은 밖에서 <code>$( )</code>로 감싸는 순간 하나의 <strong>반환 문자열</strong>로 합쳐집니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">my_func() {
    printf "Hello "
    printf "World"
}

RESULT=$(my_func)
# RESULT에는 "Hello World"가 들어갑니다.</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph"><code>$?</code> 사용 시 주의 : <code>$?</code>는 <strong>바로 직전 명령의 상태코드</strong>라서 즉시 변수에 저장하는 습관이 중요해요.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">STATUS_CODE=$?   # 이 줄은 OK

# 하지만 이런 경우 주의!
some_func
echo "결과 출력"   # 이 줄이 실행되면 $?가 덮어씌워짐
echo $?            # some_func의 코드가 아님!</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph"><code>$()</code>와 서브쉘 비용</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">RESULT=$(my_func)  # 서브쉘이 생성됨 → 성능 비용 있음</pre>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://lycos7560.com/etc/posix-shell-%ed%91%9c%ec%a4%80-%ed%95%a8%ec%88%98function/40616/">POSIX Shell: 표준 함수(Function)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/etc/posix-shell-%ed%91%9c%ec%a4%80-%ed%95%a8%ec%88%98function/40616/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>POSIX Shell: if</title>
		<link>https://lycos7560.com/etc/posix-shell-if/40609/</link>
					<comments>https://lycos7560.com/etc/posix-shell-if/40609/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 12 May 2026 21:11:09 +0000</pubDate>
				<category><![CDATA[개인 공부 저장용]]></category>
		<category><![CDATA[기타]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40609</guid>

					<description><![CDATA[<p>쉘 스크립트에서 if문은 프로그램의 흐름을 결정하는 핵심입니다. 하지만 #!/bin/sh 환경에서는 우리가 흔히 쓰는 Bash 전용 문법([[ ]])을 사용할 수 없습니다. 어디서나 돌아가는 견고한 스크립트를 위한 POSIX 표준 if 문법을 정리합니다. 기본 구조 가장 중요한 것은 if, then, fi의 짝을 맞추는 것입니다. 주의: [ 뒤와 ] 앞에는 반드시 공백이 있어야 합니다. [는 사실 test라는 이름의 명령어이기 [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/etc/posix-shell-if/40609/">POSIX Shell: if</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-9a16a507      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#기본-구조" class="uagb-toc-link__trigger">기본 구조</a><li class="uagb-toc__list"><a href="#문자열-비교-string-comparison" class="uagb-toc-link__trigger">문자열 비교 (String Comparison)</a><li class="uagb-toc__list"><a href="#숫자-비교-integer-comparison" class="uagb-toc-link__trigger">숫자 비교 (Integer Comparison)</a><li class="uagb-toc__list"><a href="#파일-상태-확인-file-test" class="uagb-toc-link__trigger">파일 상태 확인 (File Test)</a><li class="uagb-toc__list"><a href="#논리-연산-and-or" class="uagb-toc-link__trigger">논리 연산 (AND, OR)</a><li class="uagb-toc__list"><a href="#사용-예시" class="uagb-toc-link__trigger">사용 예시</a></ol>					</div>
									</div>
				</div>
			


<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">쉘 스크립트에서 <code>if</code>문은 프로그램의 흐름을 결정하는 핵심입니다. </p>



<p class="wp-block-paragraph">하지만 <code>#!/bin/sh</code> 환경에서는 우리가 흔히 쓰는 Bash 전용 문법(<code>[[ ]]</code>)을 사용할 수 없습니다. </p>



<p class="wp-block-paragraph">어디서나 돌아가는 견고한 스크립트를 위한 <strong>POSIX 표준 if 문법</strong>을 정리합니다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">기본 구조</h2>



<p class="wp-block-paragraph">가장 중요한 것은 <strong><code>if</code></strong>, <strong><code>then</code></strong>, <code><strong>fi</strong></code>의 짝을 맞추는 것입니다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">if [ 조건식 ]; then
    # 조건이 참(True)일 때 실행
elif [ 조건식 ]; then
    # 앞의 조건이 거짓이고, 현재 조건이 참일 때 실행
else
    # 모든 조건이 거짓일 때 실행
fi</pre>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph"><strong>주의:</strong> <code>[</code> 뒤와 <code>]</code> 앞에는 반드시 <strong>공백</strong>이 있어야 합니다. <code>[</code>는 사실 <code>test</code>라는 이름의 명령어이기 때문입니다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문자열 비교 (String Comparison)</h2>



<p class="wp-block-paragraph">문자열을 비교할 때는 <code>=</code>와 <code>!=</code>를 사용합니다.</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><td><strong>조건식</strong></td><td><strong>설명</strong></td></tr></thead><tbody><tr><td><code>[ "$A" = "$B" ]</code></td><td>A와 B가 같으면 참</td></tr><tr><td><code>[ "$A" != "$B" ]</code></td><td>A와 B가 다르면 참</td></tr><tr><td><code>[ -z "$A" ]</code></td><td>문자열 A의 길이가 0이면 참 (Empty)</td></tr><tr><td><code>[ -n "$A" ]</code></td><td>문자열 A의 길이가 0이 아니면 참 (Not Empty)</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>핵심 팁:</strong> 변수는 반드시 <strong>쌍따옴표(<code>" "</code>)</strong>로 감싸세요. </p>



<p class="wp-block-paragraph">변수가 비어있을 경우 발생할 수 있는 구문 오류를 방지해줍니다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">숫자 비교 (Integer Comparison)</h2>



<p class="wp-block-paragraph">숫자는 부등호(<code>&lt;</code>, <code>></code>) 대신 <strong>문자 약어</strong>를 사용합니다.</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><td><strong>조건식</strong></td><td><strong>의미</strong></td><td><strong>Full Name</strong></td></tr></thead><tbody><tr><td><code>[ "$A" -eq "$B" ]</code></td><td>같음</td><td><strong>Eq</strong>ual</td></tr><tr><td><code>[ "$A" -ne "$B" ]</code></td><td>다름</td><td><strong>N</strong>ot <strong>E</strong>qual</td></tr><tr><td><code>[ "$A" -gt "$B" ]</code></td><td>초과</td><td><strong>G</strong>reater <strong>T</strong>han</td></tr><tr><td><code>[ "$A" -ge "$B" ]</code></td><td>이상</td><td><strong>G</strong>reater or <strong>E</strong>qual</td></tr><tr><td><code>[ "$A" -lt "$B" ]</code></td><td>미만</td><td><strong>L</strong>ess <strong>T</strong>han</td></tr><tr><td><code>[ "$A" -le "$B" ]</code></td><td>이하</td><td><strong>L</strong>ess or <strong>E</strong>qual</td></tr></tbody></table></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">파일 상태 확인 (File Test)</h2>



<p class="wp-block-paragraph">쉘 스크립트에서 가장 많이 쓰이는 강력한 기능입니다.</p>



<ul class="wp-block-list">
<li><code>[ -f "file" ]</code>: 일반 <strong>파일</strong>이 존재하면 참</li>



<li><code>[ -d "dir" ]</code>: <strong>디렉토리</strong>가 존재하면 참</li>



<li><code>[ -e "path" ]</code>: 파일이든 디렉토리든 <strong>존재</strong>만 하면 참</li>



<li><code>[ -r "file" ]</code>: 읽기 권한이 있으면 참</li>



<li><code>[ -x "file" ]</code>: 실행 권한이 있으면 참</li>
</ul>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">논리 연산 (AND, OR)</h2>



<p class="wp-block-paragraph">여러 조건을 조합할 때 POSIX에서는 두 가지 방법을 씁니다.</p>



<p class="wp-block-paragraph"><strong><code>-a</code> (AND), <code>-o</code> (OR)</strong>: 하나의 <code>[ ]</code> 안에서 사용</p>



<ul class="wp-block-list">
<li><code>if [ "$A" = "1" -a "$B" = "2" ]</code></li>
</ul>



<p class="wp-block-paragraph"><strong><code>&amp;&amp;</code>, <code>||</code> 활용</strong>: 여러 개의 <code>[ ]</code>를 연결 (<strong>더 권장됨</strong>)</p>



<ul class="wp-block-list">
<li><code>if [ "$A" = "1" ] &amp;&amp; [ "$B" = "2" ]</code></li>
</ul>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">사용 예시</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh

APP_NAME="TestApp"
CONFIG_FILE="./config.conf"
DEBUG_MODE="ON"

printf "시스템 체크를 시작합니다...\n"

# 1. 설정 파일 존재 여부 체크 (파일 테스트)
if [ -f "$CONFIG_FILE" ]; then
    printf "[OK] 설정 파일을 찾았습니다.\n"
else
    printf "[Error] %s 파일이 없습니다.\n" "$CONFIG_FILE"
    # exit 1  # 실제 스크립트라면 여기서 종료 가능
fi

# 2. 디버그 모드 확인 (문자열 비교)
if [ "$DEBUG_MODE" = "ON" ]; then
    printf "[Log] 디버그 모드가 활성화되어 있습니다.\n"
fi

# 3. 인자 개수 확인 (숫자 비교)
# $#는 스크립트에 전달된 인자의 개수입니다.
if [ "$#" -lt 1 ]; then
    printf "사용법: %s [start|stop]\n" "$0"
else
    if [ "$1" = "start" ]; then
        printf "%s을 시작합니다...\n" "$APP_NAME"
    elif [ "$1" = "stop" ]; then
        printf "%s을 중지합니다...\n" "$APP_NAME"
    else
        printf "알 수 없는 명령입니다: %s\n" "$1"
    fi
fi





$ ./01_hello.sh start
시스템 체크를 시작합니다...
[OK] 설정 파일을 찾았습니다.
[Log] 디버그 모드가 활성화되어 있습니다.
TestApp을 시작합니다...</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://lycos7560.com/etc/posix-shell-if/40609/">POSIX Shell: if</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/etc/posix-shell-if/40609/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>POSIX Shell: printf</title>
		<link>https://lycos7560.com/etc/posix-bash-printf/40604/</link>
					<comments>https://lycos7560.com/etc/posix-bash-printf/40604/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 12 May 2026 20:50:44 +0000</pubDate>
				<category><![CDATA[개인 공부 저장용]]></category>
		<category><![CDATA[기타]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40604</guid>

					<description><![CDATA[<p>쉘 스크립트를 작성할 때 단순히 메시지를 출력하기 위해 echo를 자주 사용합니다. 하지만 스크립트가 복잡해지고 여러 환경에서의 이식성(Portability)이 중요해지면 printf를 사용하는 것이 개발자 정신 건강에 좋다. echo 대신 printf? 특징 echo printf 표준 준수 시스템/쉘마다 동작이 다름 (비표준) POSIX 표준 — 어디서나 동일하게 동작 제어 능력 단순 출력에 최적화 포맷 지정자를 통한 세밀한 제어 가능 개행(줄바꿈) [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/etc/posix-bash-printf/40604/">POSIX Shell: printf</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-db47f186      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#echo-대신-printf" class="uagb-toc-link__trigger">echo 대신 printf?</a><li class="uagb-toc__list"><a href="#기본-문법" class="uagb-toc-link__trigger">기본 문법</a><li class="uagb-toc__list"><a href="#핵심-포맷-지정자-format-specifiers" class="uagb-toc-link__trigger">핵심 포맷 지정자 (Format Specifiers)</a><li class="uagb-toc__list"><a href="#고급-제어-너비-정렬-정밀도" class="uagb-toc-link__trigger">고급 제어: 너비, 정렬, 정밀도</a><li class="uagb-toc__list"><a href="#실전-예제-코드" class="uagb-toc-link__trigger">실전 예제 코드</a><li class="uagb-toc__list"><a href="#이스케이프-시퀀스-escape-sequences" class="uagb-toc-link__trigger">이스케이프 시퀀스 (Escape Sequences)</a></ol>					</div>
									</div>
				</div>
			


<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">쉘 스크립트를 작성할 때 단순히 메시지를 출력하기 위해 <code>echo</code>를 자주 사용합니다. </p>



<p class="wp-block-paragraph">하지만 스크립트가 복잡해지고 여러 환경에서의 이식성(Portability)이 중요해지면 <code>printf</code>를 사용하는 것이 개발자 정신 건강에 좋다.</p>



<h2 class="wp-block-heading">echo 대신 printf?</h2>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><td><strong>특징</strong></td><td><strong>echo</strong></td><td><strong>printf</strong></td></tr></thead><tbody><tr><td><strong>표준 준수</strong></td><td>시스템/쉘마다 동작이 다름 (비표준)</td><td><strong>POSIX 표준</strong> — 어디서나 동일하게 동작</td></tr><tr><td><strong>제어 능력</strong></td><td>단순 출력에 최적화</td><td>포맷 지정자를 통한 세밀한 제어 가능</td></tr><tr><td><strong>개행(줄바꿈)</strong></td><td>자동으로 줄을 바꿈</td><td><code>\n</code>을 명시해야 함 (의도적 제어 가능)</td></tr><tr><td><strong>신뢰도</strong></td><td><code>-e</code>, <code>-n</code> 옵션 등이 환경마다 다름</td><td>일관된 결과 보장 (이식성 높음)</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>결론:</strong> 단순한 확인용 출력은 <code>echo</code>가 편하지만, 표(Table)를 만들거나 진법 변환, 정교한 텍스트 배치가 필요하다면 <code>printf</code>를 사용하는 것이 좋다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">기본 문법</h2>



<p class="wp-block-paragraph"><code>printf</code>는 포맷 문자열(Format String)을 먼저 정의하고, 그 뒤에 들어갈 인자(Arguments)를 순서대로 나열하는 문법 체계를 가지고 있다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">printf "포맷문자열" [인자1] [인자2] ...</pre>



<ul class="wp-block-list">
<li><strong>특징</strong>: 인자의 개수가 포맷 지정자보다 많으면, 포맷 문자열을 <strong>반복</strong>해서 적용합니다.</li>



<li><strong>주의</strong>: 자동으로 줄바꿈을 하지 않으므로 문자열 끝에 <code>\n</code>을 붙여야 합니다</li>
</ul>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">핵심 포맷 지정자 (Format Specifiers)</h2>



<p class="wp-block-paragraph">인자의 데이터 타입에 맞는 지정자를 사용해야 합니다.</p>



<ul class="wp-block-list">
<li><code>%s</code>: <strong>S</strong>tring (문자열)</li>



<li><code>%d</code>: <strong>D</strong>ecimal (10진수 정수)</li>



<li><code>%f</code>: <strong>F</strong>loat (부동소수점 실수)</li>



<li><code>%x</code>: He<strong>x</strong>adecimal (16진수 소문자)</li>



<li><code>%o</code>: <strong>O</strong>ctal (8진수)</li>



<li><code>%%</code>: <code>%</code> 기호 자체를 출력</li>
</ul>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">고급 제어: 너비, 정렬, 정밀도</h2>



<p class="wp-block-paragraph"><code>printf</code>의 진가는 데이터를 예쁘게 정렬할 때 나타납니다.</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><td><strong>포맷</strong></td><td><strong>설명</strong></td></tr></thead><tbody><tr><td><code>%10s</code></td><td>최소 10자 너비 확보, <strong>오른쪽</strong> 정렬</td></tr><tr><td><code>%-10s</code></td><td>최소 10자 너비 확보, <strong>왼쪽</strong> 정렬</td></tr><tr><td><code>%.2f</code></td><td>소수점 아래 <strong>2자리</strong>까지 출력</td></tr><tr><td><code>%8.2f</code></td><td>전체 8칸 확보 후 소수점 2자리 출력</td></tr></tbody></table></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">실전 예제 코드</h2>



<p class="wp-block-paragraph">기본 출력 및 진법 변환</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># 이름과 나이 출력
printf "이름: %s, 나이: %d\n" "Kim" 30

# 10진수 255를 16진수로 변환 (결과: 0xff)
printf "16진수 변환: 0x%x\n" 255

# 퍼센트 기호 출력 (결과: 75%)
printf "CPU 사용률: %d%%\n" 75</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">데이터 표(Table) 만들기</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh

# 헤더 출력
printf "%-10s %5s %8s\n" "이름" "점수" "등급"
printf "--------------------------\n"

# 데이터 출력
printf "%-10s %5d %8s\n" "홍길동" 95 "A"
printf "%-10s %5d %8s\n" "김철수" 82 "B"
printf "%-10s %5d %8s\n" "이영희" 100 "A+"</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">이스케이프 시퀀스 (Escape Sequences)</h2>



<p class="wp-block-paragraph">문자열 내에서 특수 기능을 수행하는 기호들입니다.</p>



<ul class="wp-block-list">
<li><code>\n</code>: 줄바꿈 (Newline)</li>



<li><code>\t</code>: 탭 (Tab)</li>



<li><code>\\</code>: 백슬래시(<code>\</code>) 자체 출력</li>



<li><code>\0NNN</code>: 8진수 숫자로 지정된 ASCII 문자 출력</li>
</ul>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://lycos7560.com/etc/posix-bash-printf/40604/">POSIX Shell: printf</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/etc/posix-bash-printf/40604/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Linux 타임존 변경 (timedatectl)</title>
		<link>https://lycos7560.com/%eb%af%b8-%eb%b6%84%eb%a5%98/linux-%ed%83%80%ec%9e%84%ec%a1%b4-%eb%b3%80%ea%b2%bd/40594/</link>
					<comments>https://lycos7560.com/%eb%af%b8-%eb%b6%84%eb%a5%98/linux-%ed%83%80%ec%9e%84%ec%a1%b4-%eb%b3%80%ea%b2%bd/40594/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 11 May 2026 20:37:30 +0000</pubDate>
				<category><![CDATA[미분류]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40594</guid>

					<description><![CDATA[<p>타임존 변경은 대부분의 Linux 배포판에서 공통으로 사용 가능한 timedatectl 명령어로 처리 적용 대상 배포판 timedatectl 은 systemd 기반 배포판이면 공통으로 사용 가능 배포판 사용 가능 여부 Rocky Linux / AlmaLinux / RHEL ✅ CentOS ✅ Ubuntu / Debian ✅ Fedora ✅ openSUSE ✅ Arch Linux ✅ 타임존 변경 방법 사용 가능한 타임존 목록 확인 타임존 [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/%eb%af%b8-%eb%b6%84%eb%a5%98/linux-%ed%83%80%ec%9e%84%ec%a1%b4-%eb%b3%80%ea%b2%bd/40594/">Linux 타임존 변경 (timedatectl)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">타임존 변경은 대부분의 Linux 배포판에서 공통으로 사용 가능한 <code>timedatectl</code> 명령어로 처리</p>



<h3 class="wp-block-heading">적용 대상 배포판</h3>



<p class="wp-block-paragraph"><code>timedatectl</code> 은 <strong>systemd 기반 배포판</strong>이면 공통으로 사용 가능</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>배포판</th><th>사용 가능 여부</th></tr></thead><tbody><tr><td>Rocky Linux / AlmaLinux / RHEL</td><td><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /></td></tr><tr><td>CentOS</td><td><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /></td></tr><tr><td>Ubuntu / Debian</td><td><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /></td></tr><tr><td>Fedora</td><td><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /></td></tr><tr><td>openSUSE</td><td><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /></td></tr><tr><td>Arch Linux</td><td><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /></td></tr></tbody></table></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">타임존 변경 방법</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">timedatectl

[root@localhost /]# timedatectl
               Local time: Mon 2026-05-11 16:32:51 EDT
           Universal time: Mon 2026-05-11 20:32:51 UTC
                 RTC time: Mon 2026-05-11 20:32:50
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">사용 가능한 타임존 목록 확인</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">timedatectl list-timezones

[root@localhost /]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
...


timedatectl list-timezones | grep Asia/Seoul

[root@localhost /]# timedatectl list-timezones | grep Asia/Seoul
Asia/Seoul</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">타임존 변경</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">timedatectl set-timezone Asia/Seoul

[root@localhost /]# timedatectl
               Local time: Tue 2026-05-12 05:35:14 KST
           Universal time: Mon 2026-05-11 20:35:14 UTC
                 RTC time: Mon 2026-05-11 20:35:14
                Time zone: Asia/Seoul (KST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">주요 타임존 목록</h2>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>지역</th><th>타임존</th><th>표준시</th></tr></thead><tbody><tr><td>한국</td><td><code>Asia/Seoul</code></td><td>KST +0900</td></tr><tr><td>일본</td><td><code>Asia/Tokyo</code></td><td>JST +0900</td></tr><tr><td>중국</td><td><code>Asia/Shanghai</code></td><td>CST +0800</td></tr><tr><td>미국 동부</td><td><code>America/New_York</code></td><td>EST -0500</td></tr><tr><td>미국 서부</td><td><code>America/Los_Angeles</code></td><td>PST -0800</td></tr><tr><td>영국</td><td><code>Europe/London</code></td><td>GMT +0000</td></tr><tr><td>독일</td><td><code>Europe/Berlin</code></td><td>CET +0100</td></tr><tr><td>UTC</td><td><code>UTC</code></td><td>UTC +0000</td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--40);margin-bottom:var(--wp--preset--spacing--40)"/>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">NTP 시간 동기화 확인</h3>



<p class="wp-block-paragraph">타임존 변경 후 시간이 맞지 않으면 NTP 동기화 상태를 확인</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">timedatectl set-ntp true
timedatectl status

[root@localhost /]# timedatectl set-ntp true
[root@localhost /]# timedatectl status
               Local time: Tue 2026-05-12 05:36:39 KST
           Universal time: Mon 2026-05-11 20:36:39 UTC
                 RTC time: Mon 2026-05-11 20:36:39
                Time zone: Asia/Seoul (KST, +0900)
System clock synchronized: yes  // 정상
              NTP service: active
          RTC in local TZ: no
</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://lycos7560.com/%eb%af%b8-%eb%b6%84%eb%a5%98/linux-%ed%83%80%ec%9e%84%ec%a1%b4-%eb%b3%80%ea%b2%bd/40594/">Linux 타임존 변경 (timedatectl)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/%eb%af%b8-%eb%b6%84%eb%a5%98/linux-%ed%83%80%ec%9e%84%ec%a1%b4-%eb%b3%80%ea%b2%bd/40594/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Rocky Linux 10.1 노트북 절전 모드 관련</title>
		<link>https://lycos7560.com/%eb%af%b8-%eb%b6%84%eb%a5%98/rocky-linux-10-1-%eb%85%b8%ed%8a%b8%eb%b6%81-%ec%a0%88%ec%a0%84-%eb%aa%a8%eb%93%9c-%ea%b4%80%eb%a0%a8/40590/</link>
					<comments>https://lycos7560.com/%eb%af%b8-%eb%b6%84%eb%a5%98/rocky-linux-10-1-%eb%85%b8%ed%8a%b8%eb%b6%81-%ec%a0%88%ec%a0%84-%eb%aa%a8%eb%93%9c-%ea%b4%80%eb%a0%a8/40590/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 11 May 2026 19:29:05 +0000</pubDate>
				<category><![CDATA[미분류]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40590</guid>

					<description><![CDATA[<p>덮개(Lid)를 닫으면 절전 모드로 진입하여 SSH 접속이 끊기는 문제 Rocky Linux 10.1은 systemd-logind가 노트북 덮개 이벤트를 관리하며, 기본값은 덮개를 닫으면 suspend(절전) 해당 문제를 해결하려면 /etc/systemd/logind.conf 수정이 필요</p>
<p>The post <a href="https://lycos7560.com/%eb%af%b8-%eb%b6%84%eb%a5%98/rocky-linux-10-1-%eb%85%b8%ed%8a%b8%eb%b6%81-%ec%a0%88%ec%a0%84-%eb%aa%a8%eb%93%9c-%ea%b4%80%eb%a0%a8/40590/">Rocky Linux 10.1 노트북 절전 모드 관련</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">환경 
ROG G713RM
- AMD Ryzen<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2122.png" alt="™" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 7 6800H Mobile Processor (8-core/16-thread, 20MB cache)
- NVIDIA® GeForce RTX<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2122.png" alt="™" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 3060 Laptop GPU (6GB GDDR6)

OS: Rocky Linux 10.1 (Red Quartz) / 미니멀 설치</pre>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph"><strong>덮개(Lid)를 닫으면 절전 모드로 진입</strong>하여 SSH 접속이 끊기는 문제</p>



<p class="wp-block-paragraph">Rocky Linux 10.1은 <code>systemd-logind</code>가 노트북 덮개 이벤트를 관리하며, 기본값은 덮개를 닫으면 <strong>suspend(절전)</strong></p>



<p class="wp-block-paragraph">해당 문제를 해결하려면 /etc/systemd/logind.conf 수정이 필요</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">설정 파일 위치:
/etc/systemd/logind.conf
Minimal라면 해당 파일이 없을 수 있음(기본 컴파일된 값을 사용)

기본값:
[Login]
#HandleLidSwitch=suspend  // 배터리 전원 시 덮개 닫힘 동작
#HandleLidSwitchExternalPower=suspend // 외부 전원(어댑터) 연결 시 덮개 닫힘 동작
#HandleLidSwitchDocked=ignore // 도킹 스테이션 연결 시 덮개 닫힘 동작

-> 기본값이 suspend이기 때문에 덮개를 닫으면 절전 모드로 진입

ignore - 덮개 닫힘 이벤트 무시 (아무 동작 안 함)
suspend - 절전 모드 진입 (기본값)
poweroff - 전원 끄기
hibernate - 최대 절전 모드

아래와 같이 변경 (파일이 없다면 생)
[Login]
HandleLidSwitch=ignore                 
HandleLidSwitchExternalPower=ignore    
HandleLidSwitchDocked=ignore

변경 후 재시작
systemctl restart systemd-logind
</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">[root@localhost systemd]# sudo systemctl status systemd-logind
● systemd-logind.service - User Login Management
     Loaded: loaded (/usr/lib/systemd/system/systemd-logind.service; static)
    Drop-In: /usr/lib/systemd/system/systemd-logind.service.d
             └─10-grub2-logind-service.conf
     Active: active (running) since Mon 2026-05-11 15:04:29 EDT; 18min ago
 Invocation: ca4ede52e7fd465c92035c1e244e2cbd
       Docs: man:sd-login(3)
             man:systemd-logind.service(8)
             man:logind.conf(5)
             man:org.freedesktop.login1(5)
   Main PID: 2762 (systemd-logind)
     Status: "Processing requests..."
      Tasks: 1 (limit: 197880)
   FD Store: 4 (limit: 768)
     Memory: 3.1M (peak: 6.8M)
        CPU: 123ms
     CGroup: /system.slice/systemd-logind.service
             └─2762 /usr/lib/systemd/systemd-logind

May 11 15:04:29 localhost.localdomain systemd-logind[2762]: Watching system buttons on /dev/input/event1 (Power Button)
May 11 15:04:29 localhost.localdomain systemd-logind[2762]: Watching system buttons on /dev/input/event2 (Sleep Button)
May 11 15:04:29 localhost.localdomain systemd-logind[2762]: Watching system buttons on /dev/input/event4 (Asus Keyboard)
May 11 15:04:29 localhost.localdomain systemd-logind[2762]: Watching system buttons on /dev/input/event3 (AT Translated Set 2 keyboard)
→ 전원버튼, 슬립버튼, 키보드 등 하드웨어 이벤트를 감시 중

May 11 15:04:29 localhost.localdomain systemd-logind[2762]: New session 1 of user root.
May 11 15:04:29 localhost.localdomain systemd[1]: Started systemd-logind.service - User Login Management.
May 11 15:04:44 localhost.localdomain systemd-logind[2762]: Lid closed.        → 덮개 닫힘 이벤트를 감지했다는 로그
</pre>
<p>The post <a href="https://lycos7560.com/%eb%af%b8-%eb%b6%84%eb%a5%98/rocky-linux-10-1-%eb%85%b8%ed%8a%b8%eb%b6%81-%ec%a0%88%ec%a0%84-%eb%aa%a8%eb%93%9c-%ea%b4%80%eb%a0%a8/40590/">Rocky Linux 10.1 노트북 절전 모드 관련</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/%eb%af%b8-%eb%b6%84%eb%a5%98/rocky-linux-10-1-%eb%85%b8%ed%8a%b8%eb%b6%81-%ec%a0%88%ec%a0%84-%eb%aa%a8%eb%93%9c-%ea%b4%80%eb%a0%a8/40590/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>#include 지시자</title>
		<link>https://lycos7560.com/etc/include-%ec%a7%80%ec%8b%9c%ec%9e%90/40565/</link>
					<comments>https://lycos7560.com/etc/include-%ec%a7%80%ec%8b%9c%ec%9e%90/40565/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 05 Apr 2026 18:33:13 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[개인 공부 저장용]]></category>
		<category><![CDATA[기타]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40565</guid>

					<description><![CDATA[<p>C 언어와 C++에서 #include는 소스 코드 파일의 가장 윗부분에서 흔히 볼 수 있는 전처리기 지시자(Preprocessor Directive)입니다. 1. #include의 핵심 역할 #include는 한마디로 &#8220;복사해서 붙여넣기&#8221;입니다. 컴파일러가 실제 코드를 번역하기 전(전처리 단계), 지정한 파일의 내용을 #include 문장이 있는 그 자리에 통째로 가져와서 삽입합니다. 2. 사용법에 따른 차이 ( &#60; &#62; vs " " ) #include를 사용할 때 [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/etc/include-%ec%a7%80%ec%8b%9c%ec%9e%90/40565/">#include 지시자</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-537dce7c      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#1-include의-핵심-역할" class="uagb-toc-link__trigger">1. #include의 핵심 역할</a><li class="uagb-toc__list"><a href="#2-사용법에-따른-차이-vs" class="uagb-toc-link__trigger">2. 사용법에 따른 차이 ( &lt; &gt; vs &quot; &quot; )</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#꺽쇠-괄호" class="uagb-toc-link__trigger">① &lt; &gt; (꺽쇠 괄호)</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#큰따옴표" class="uagb-toc-link__trigger">② &quot; &quot; (큰따옴표)</a></li></ul></li><li class="uagb-toc__list"><a href="#3-왜-헤더-파일을-포함해야-할까" class="uagb-toc-link__trigger">3. 왜 헤더 파일을 포함해야 할까?</a><li class="uagb-toc__list"><a href="#4-주의사항-중복-포함-방지" class="uagb-toc-link__trigger">4. 주의사항: 중복 포함 방지</a><li class="uagb-toc__list"><a href="#5-자주-사용하는-표준-라이브러리-헤더-목록-c" class="uagb-toc-link__trigger">5. 자주 사용하는 표준 라이브러리 헤더 목록 (c)</a><li class="uagb-toc__list"><a href="#요약" class="uagb-toc-link__trigger"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4a1.png" alt="💡" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 요약</a></ul></ol>					</div>
									</div>
				</div>
			


<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">C 언어와 C++에서 <code>#include</code>는 소스 코드 파일의 가장 윗부분에서 흔히 볼 수 있는 전처리기 지시자(Preprocessor Directive)입니다. </p>



<h2 class="wp-block-heading">1. <code>#include</code>의 핵심 역할</h2>



<p class="wp-block-paragraph"><code>#include</code>는 한마디로 <strong>&#8220;복사해서 붙여넣기&#8221;</strong>입니다. </p>



<p class="wp-block-paragraph">컴파일러가 실제 코드를 번역하기 전(전처리 단계), 지정한 파일의 내용을 <code>#include</code> 문장이 있는 그 자리에 통째로 가져와서 삽입합니다.</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="644" height="299" src="https://lycos7560.com/wp-content/uploads/2026/04/image.png" alt="" class="wp-image-40566" srcset="https://lycos7560.com/wp-content/uploads/2026/04/image.png 644w, https://lycos7560.com/wp-content/uploads/2026/04/image-300x139.png 300w" sizes="(max-width: 644px) 100vw, 644px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30)"/>



<h2 class="wp-block-heading">2. 사용법에 따른 차이 ( <code>&lt; &gt;</code> vs <code>" "</code> )</h2>



<p class="wp-block-paragraph"><code>#include</code>를 사용할 때 괄호의 모양에 따라 파일을 찾는 위치가 달라집니다.</p>



<h3 class="wp-block-heading">① <code>&lt; &gt;</code> (꺽쇠 괄호)</h3>



<ul class="wp-block-list">
<li><strong>사용 예:</strong> <code>#include &lt;stdio.h&gt;</code></li>



<li><strong>설명:</strong> 시스템의 <strong>표준 라이브러리 경로</strong>에서 파일을 찾습니다.</li>



<li><strong>대상:</strong> 컴파일러 설치 시 기본적으로 제공되는 표준 헤더 파일들을 불러올 때 사용합니다.</li>
</ul>



<h3 class="wp-block-heading">② <code>" "</code> (큰따옴표)</h3>



<ul class="wp-block-list">
<li><strong>사용 예:</strong> <code>#include "my_header.h"</code></li>



<li><strong>설명:</strong> <strong>현재 작업 중인 디렉토리(소스 파일이 있는 곳)</strong>에서 먼저 파일을 찾습니다. 만약 거기서 못 찾으면 시스템 표준 경로를 뒤집니다.</li>



<li><strong>대상:</strong> 개발자가 직접 만든 헤더 파일을 불러올 때 주로 사용합니다.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30)"/>



<h2 class="wp-block-heading">3. 왜 헤더 파일을 포함해야 할까?</h2>



<p class="wp-block-paragraph"><code>printf</code>나 <code>scanf</code> 같은 함수를 쓸 수 있는 이유는 그 함수들의 <strong>선언(Declaration)</strong>이 <code>stdio.h</code>라는 파일 안에 들어있기 때문입니다.</p>



<ul class="wp-block-list">
<li>컴파일러는 함수를 만나면 &#8220;이 함수가 어떻게 생겼는지(매개변수, 반환 타입 등)&#8221;를 알아야 합니다.</li>



<li>직접 모든 함수를 정의하기엔 양이 너무 많으므로, 미리 정의된 헤더 파일을 <code>#include</code>로 불러와서 정보를 제공하는 것입니다.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30)"/>



<h2 class="wp-block-heading">4. 주의사항: 중복 포함 방지</h2>



<p class="wp-block-paragraph">대규모 프로젝트에서는 여러 파일이 서로를 참조하다가 똑같은 헤더 파일을 여러 번 <code>#include</code> 하는 상황이 발생할 수 있습니다. </p>



<p class="wp-block-paragraph">이는 정의 중복 에러를 일으키므로, 보통 다음과 같은 기법을 사용합니다.</p>



<ul class="wp-block-list">
<li><strong>Header Guard:</strong>C<code>#ifndef MY_HEADER_H #define MY_HEADER_H // 코드 내용 #endif</code></li>



<li><strong>pragma once:</strong>C<code>#pragma once // 코드 내용</code></li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#ifndef MY_HEADER_H
#define MY_HEADER_H

/* 헤더 파일 내용 */
void say_hello();

#endif</pre>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30)"/>



<h2 class="wp-block-heading">5. 자주 사용하는 표준 라이브러리 헤더 목록 (c)</h2>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">헤더 파일</th><th class="has-text-align-left" data-align="left">포함 내용</th><th class="has-text-align-left" data-align="left">대표 함수</th></tr></thead><tbody><tr><td>&lt;stdio.h&gt;</td><td>표준 입출력</td><td>printf, scanf, fopen</td></tr><tr><td>&lt;stdlib.h&gt;</td><td>메모리·변환·난수</td><td>malloc, free, rand</td></tr><tr><td>&lt;string.h&gt;</td><td>문자열 처리</td><td>strcpy, strlen, strcmp</td></tr><tr><td>&lt;math.h&gt;</td><td>수학 함수</td><td>sqrt, pow, sin</td></tr><tr><td>&lt;time.h&gt;</td><td>시간·날짜</td><td>time, clock, difftime</td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30)"/>



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4a1.png" alt="💡" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 요약</h2>



<p class="wp-block-paragraph"><code>#include</code>는 <strong>외부에 작성된 코드나 함수 선언을 현재 파일로 가져오는 통로</strong>입니다. </p>



<p class="wp-block-paragraph">시스템 라이브러리는 <code>&lt; &gt;</code>를, 내가 만든 파일은 <code>" "</code>를 사용합니다.</p>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://lycos7560.com/etc/include-%ec%a7%80%ec%8b%9c%ec%9e%90/40565/">#include 지시자</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/etc/include-%ec%a7%80%ec%8b%9c%ec%9e%90/40565/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
