<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Режимы bash - .bash_profile .bashrc]]></title><description><![CDATA[<p dir="auto">Bash запускается в разных режимах — и от этого зависит <strong>какие файлы он читает при старте</strong></p>
<h2>4 режима bash</h2>
<h3>Login shell (интерактивный, с входом)</h3>
<p dir="auto"><strong>Как запускается:</strong> SSH-сессия без команды, <code>su - user</code>, <code>bash -l</code></p>
<p dir="auto"><strong>Читает по порядку:</strong></p>
<pre><code>/etc/profile
  └── ~/.bash_profile  ← первый найденный из трёх:
  └── ~/.bash_login
  └── ~/.profile
</code></pre>
<p dir="auto">При выходе читает <code>~/.bash_logout</code>.</p>
<pre><code class="language-bash"># Примеры:
ssh user@server          # интерактивная ssh-сессия
bash -l                  # явно запустить login shell
su - admin               # переключиться с login
</code></pre>
<hr />
<h3>Interactive shell (интерактивный, без входа)</h3>
<p dir="auto"><strong>Как запускается:</strong> новое окно терминала, вкладка, просто набрать <code>bash</code></p>
<p dir="auto"><strong>Читает:</strong></p>
<pre><code>/etc/bash.bashrc  (на Debian/Ubuntu)
~/.bashrc
</code></pre>
<pre><code class="language-bash"># Примеры:
bash                     # запустить дочерний bash
xterm                    # открыть новый терминал
tmux / screen            # новое окно
</code></pre>
<hr />
<h3>Non-interactive, non-login ← <strong>самый частый источник проблем</strong></h3>
<p dir="auto"><strong>Как запускается:</strong> <code>ssh user@host "команда"</code>, запуск скрипта через <code>bash script.sh</code></p>
<p dir="auto"><strong>Читает: ничего</strong></p>
<pre><code class="language-bash"># Примеры — ничего не работает:
ssh user@host "pm2 restart app"   # PATH пустой
bash deploy.sh                    # nvm/fnm недоступны
cron jobs                         # тоже сюда
</code></pre>
<hr />
<h3>Non-interactive login shell</h3>
<p dir="auto"><strong>Как запускается:</strong> <code>bash -lc "команда"</code>, <code>ssh user@host bash -lc "..."</code></p>
<p dir="auto"><strong>Читает:</strong> <code>~/.bash_profile</code> (и цепочку из п.1)</p>
<pre><code class="language-bash"># Примеры — работает если настроен bash_profile:
ssh user@host 'bash -lc "pm2 restart app"'   # ✅
bash -lc "node --version"                    # ✅
</code></pre>
<hr />
<h2>Полная таблица</h2>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="text-align:left">Режим</th>
<th style="text-align:left">Пример запуска</th>
<th style="text-align:center"><code>/etc/profile</code></th>
<th style="text-align:center"><code>~/.bash_profile</code></th>
<th style="text-align:center"><code>~/.bashrc</code></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">Login interactive</td>
<td style="text-align:left"><code>ssh user@host</code></td>
<td style="text-align:center"><img src="https://forum.exlends.com/assets/plugins/nodebb-plugin-emoji/emoji/android/2705.png?v=a9b928d4b2f" class="not-responsive emoji emoji-android emoji--white_check_mark" style="height:23px;width:auto;vertical-align:middle" title="✅" alt="✅" /></td>
<td style="text-align:center"><img src="https://forum.exlends.com/assets/plugins/nodebb-plugin-emoji/emoji/android/2705.png?v=a9b928d4b2f" class="not-responsive emoji emoji-android emoji--white_check_mark" style="height:23px;width:auto;vertical-align:middle" title="✅" alt="✅" /></td>
<td style="text-align:center"><img src="https://forum.exlends.com/assets/plugins/nodebb-plugin-emoji/emoji/android/274c.png?v=a9b928d4b2f" class="not-responsive emoji emoji-android emoji--x" style="height:23px;width:auto;vertical-align:middle" title="❌" alt="❌" /></td>
</tr>
<tr>
<td style="text-align:left">Non-login interactive</td>
<td style="text-align:left">Открыть терминал</td>
<td style="text-align:center"><img src="https://forum.exlends.com/assets/plugins/nodebb-plugin-emoji/emoji/android/274c.png?v=a9b928d4b2f" class="not-responsive emoji emoji-android emoji--x" style="height:23px;width:auto;vertical-align:middle" title="❌" alt="❌" /></td>
<td style="text-align:center"><img src="https://forum.exlends.com/assets/plugins/nodebb-plugin-emoji/emoji/android/274c.png?v=a9b928d4b2f" class="not-responsive emoji emoji-android emoji--x" style="height:23px;width:auto;vertical-align:middle" title="❌" alt="❌" /></td>
<td style="text-align:center"><img src="https://forum.exlends.com/assets/plugins/nodebb-plugin-emoji/emoji/android/2705.png?v=a9b928d4b2f" class="not-responsive emoji emoji-android emoji--white_check_mark" style="height:23px;width:auto;vertical-align:middle" title="✅" alt="✅" /></td>
</tr>
<tr>
<td style="text-align:left">Non-interactive non-login</td>
<td style="text-align:left"><code>ssh user@host "cmd"</code></td>
<td style="text-align:center"><img src="https://forum.exlends.com/assets/plugins/nodebb-plugin-emoji/emoji/android/274c.png?v=a9b928d4b2f" class="not-responsive emoji emoji-android emoji--x" style="height:23px;width:auto;vertical-align:middle" title="❌" alt="❌" /></td>
<td style="text-align:center"><img src="https://forum.exlends.com/assets/plugins/nodebb-plugin-emoji/emoji/android/274c.png?v=a9b928d4b2f" class="not-responsive emoji emoji-android emoji--x" style="height:23px;width:auto;vertical-align:middle" title="❌" alt="❌" /></td>
<td style="text-align:center"><img src="https://forum.exlends.com/assets/plugins/nodebb-plugin-emoji/emoji/android/274c.png?v=a9b928d4b2f" class="not-responsive emoji emoji-android emoji--x" style="height:23px;width:auto;vertical-align:middle" title="❌" alt="❌" /></td>
</tr>
<tr>
<td style="text-align:left">Non-interactive login</td>
<td style="text-align:left"><code>bash -lc "cmd"</code></td>
<td style="text-align:center"><img src="https://forum.exlends.com/assets/plugins/nodebb-plugin-emoji/emoji/android/2705.png?v=a9b928d4b2f" class="not-responsive emoji emoji-android emoji--white_check_mark" style="height:23px;width:auto;vertical-align:middle" title="✅" alt="✅" /></td>
<td style="text-align:center"><img src="https://forum.exlends.com/assets/plugins/nodebb-plugin-emoji/emoji/android/2705.png?v=a9b928d4b2f" class="not-responsive emoji emoji-android emoji--white_check_mark" style="height:23px;width:auto;vertical-align:middle" title="✅" alt="✅" /></td>
<td style="text-align:center"><img src="https://forum.exlends.com/assets/plugins/nodebb-plugin-emoji/emoji/android/274c.png?v=a9b928d4b2f" class="not-responsive emoji emoji-android emoji--x" style="height:23px;width:auto;vertical-align:middle" title="❌" alt="❌" /></td>
</tr>
</tbody>
</table>
<hr />
<h2>Типичная схема настройки</h2>
<p dir="auto">Именно поэтому рекомендуют делать так:</p>
<pre><code>~/.bash_profile
  └── source ~/.bashrc   ← подтягивает всё из bashrc в login-сессии
</code></pre>
<p dir="auto">Тогда и интерактивные терминалы (<code>~/.bashrc</code>), и SSH-деплой через <code>bash -lc</code> (<code>~/.bash_profile</code>) видят одно и то же окружение.</p>
<hr />
<h2>Порядок чтения <code>~/.bash_profile</code> — важный нюанс</h2>
<p dir="auto">Bash ищет <strong>первый существующий</strong> файл из трёх и читает <strong>только его</strong>:</p>
<pre><code>1. ~/.bash_profile   ← если есть — читается, остальные игнорируются
2. ~/.bash_login     ← если нет bash_profile
3. ~/.profile        ← если нет двух предыдущих
</code></pre>
<p dir="auto">На Ubuntu <code>~/.bash_profile</code> обычно отсутствует → читается <code>~/.profile</code>. На macOS — есть <code>~/.bash_profile</code>.</p>
<hr />
<h2>Применительно к деплою</h2>
<pre><code class="language-bash"># ❌ Не работает — режим 3, читает ничего
ssh "$SERVER" "pm2 restart app"

# ✅ Работает — режим 4, читает ~/.bash_profile
ssh "$SERVER" 'bash -lc "pm2 restart app"'

# ✅ Работает — если настроил ~/.bash_profile → source ~/.bashrc
# и в ~/.bashrc прописан fnm/nvm
</code></pre>
]]></description><link>https://forum.exlends.com/topic/2217/rezhimy-bash-.bash_profile-.bashrc</link><generator>RSS for Node</generator><lastBuildDate>Sat, 02 May 2026 13:07:07 GMT</lastBuildDate><atom:link href="https://forum.exlends.com/topic/2217.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 30 Apr 2026 12:25:56 GMT</pubDate><ttl>60</ttl></channel></rss>