📝

[小ネタ] CloudShell 環境を削除したら cloudshell-user@ が表示されなくなった話

2025/02/13に公開

[小ネタ] CloudShell 環境を削除してみた
上記ブログの手順で CloudShell 環境を削除したらデフォルトのプロンプトが表示されなくなった話です。

  • デフォルトの例
[cloudshell-user@ip-10-132-65-158 ~]$
  • CloudShell 環境削除後
~ $

解決策

AWS Cloudshell起動時のエラーとプロンプトの異常(userが表示されない) - eyeon -アイオン-
上記ブログの手順で解決できました。

~ $ cd ~
~ $ pwd
/home/cloudshell-user
~ $ 
~ $ printenv |grep PS1
PS1=\[\]\[\]\W $ \[\]\[\]\[\]\[\]
~ $ 
~ $ 
~ $ vi .bashrc 

export PS1="[\u@\h \W]\$ "

~ $
~ $ source .bashrc 
[cloudshell-user@ip-10-134-19-158 ~]$ 
[cloudshell-user@ip-10-134-19-158 ~]$ printenv |grep PS1
PS1=\[\][\u@\h \W]\$ \[\]\[\]
[cloudshell-user@ip-10-134-19-158 ~]$

やってみた

CloudShell 環境削除後の状態から始めます。

上記ブログのコマンドを実行しますが、.bashrc の編集は nano でやってみました。

$ cd ~
$ pwd
/home/cloudshell-user

$ printenv |grep PS1
PS1=\[\]\W $ \[\]\[\]

$ nano .bashrc

環境削除後の .bashrc は以下の状態です。

環境削除後
# Amazon Q pre block. Keep at the top of this file.
[[ -f "${HOME}/.local/share/amazon-q/shell/bashrc.pre.bash" ]] && builtin source "${HOME}/.local/share/amazon-q/shell/bashrc.pre.bash"
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
if [ -d ~/.bashrc.d ]; then
        for rc in ~/.bashrc.d/*; do
                if [ -f "$rc" ]; then
                        . "$rc"
                fi
        done
fi

unset rc
complete -C '/usr/local/bin/aws_completer' aws
export PS1='\W $ '

# Amazon Q post block. Keep at the bottom of this file.
[[ -f "${HOME}/.local/share/amazon-q/shell/bashrc.post.bash" ]] && builtin source "${HOME}/.local/share/amazon-q/shell/bashrc.post.bash"

export PS1='\W $ ' の部分を以下の値に書き換えます。

export PS1="[\u@\h \W]\$ "

念のため cat コマンドで PS1 が変更されたことを確認します。

$ cat .bashrc
# Amazon Q pre block. Keep at the top of this file.
[[ -f "${HOME}/.local/share/amazon-q/shell/bashrc.pre.bash" ]] && builtin source "${HOME}/.local/share/amazon-q/shell/bashrc.pre.bash"
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
if [ -d ~/.bashrc.d ]; then
        for rc in ~/.bashrc.d/*; do
                if [ -f "$rc" ]; then
                        . "$rc"
                fi
        done
fi

unset rc
complete -C '/usr/local/bin/aws_completer' aws
export PS1="[\u@\h \W]\$ " # 変更が反映されていることを確認

# Amazon Q post block. Keep at the bottom of this file.
[[ -f "${HOME}/.local/share/amazon-q/shell/bashrc.post.bash" ]] && builtin source "${HOME}/.local/share/amazon-q/shell/bashrc.post.bash"

変更が反映されていることを確認後、.bashrcを読み込みます。

$ source .bashrc

CloudShell 環境を再起動するか、新しいタブを開きます。

デフォルトのプロンプトに戻ったことを確認できました。

CloudShell のプロンプトを変更する方法について

CloudShell のプロンプトを変更する方法については以下のブログをご参照ください。
【小ネタ】CloudShell でプロンプトを変える方法 | DevelopersIO

まとめ

今回は CloudShell 環境を削除したら cloudshell-user@ が表示されなくなった話を紹介しました。
どなたかの参考になれば幸いです。

参考資料

Discussion