新しくインストールした後、シェルを高速化するBashスクリプトを作成しています。
main()
{
#
# By default we assume the terminal doesn't support colors
#
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
#
# Check if we are connected to a terminal, and that terminal
# supports colors.
#
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
#
# Set the colors if we can
#
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
fi
#
# Only enable exit-on-error after the non-critical colorization stuff,
# which may fail on systems lacking tput or terminfo
#
set -e
################################################################################
printf "${YELLOW}"
echo ''
echo ' ____ __ ___ _____ __ '
echo ' / __ )____ ______/ /_ |__ \/__ / _____/ /_ '
echo ' / __ / __ `/ ___/ __ \__/ / / / / ___/ __ \'
echo ' / /_/ / /_/ (__ ) / / / __/ / /__(__ ) / / /'
echo '/_____/\__,_/____/_/ /_/____/ /____/____/_/ /_/ '
echo ''
echo ''
printf "${NORMAL}"
################################################################################
#
# Find out if Zsh is already installed
#
CHECK_ZSH_INSTALLED=$(grep /zsh$ /etc/shells | wc -l)
#
# Check to see if Zsh is already installed
#
if [ ! $CHECK_ZSH_INSTALLED -ge 1 ]; then
sudo apt-get -y install zsh
fi
#
# Clean the memory
#
unset CHECK_ZSH_INSTALLED
################################################################################
#
# Remove the previous config file, so we know we start from scratch
#
rm ~/.zshrc &&
#
# Removing unnecessary Bash files
#
rm ~/.bash_history 2> /dev/null &&
rm ~/.bash_logout 2> /dev/null &&
rm ~/.bashrc 2> /dev/null &&
rm ~/.bash_sessions 2> /dev/null &&
rm ~/.sh_history 2> /dev/null &&
################################################################################
#
# Download the configuration file
#
curl -fsSL "https://raw.githubusercontent.com/davidgatti/my-development-setup/master/08_Zsh_instead_of_Bash/zshrc" >> ~/.zshrc
#
# Get the name of the logged in user
#
USER_NAME=$(whoami)
#
# Get the home path for the logged in user
#
HOME_PATH=$(getent passwd $USER_NAME | cut -d: -f6)
#
# Add a dynamic entry
#
echo 'zstyle :compinstall filename '$HOME_PATH/.zshrc'' >> ~/.zshrc
}
main
私は走り、Bash -x
すべてがうまくいきました。ただし、curl
結果の追跡では表示されません。私が試したこと:
- 変数にカールを追加
- 使用評価
"
3つの方法で設定- など。
質問
curl
リンクされたbashスクリプト内から署名されていないファイルをダウンロードしたいと思います。ここでbashスクリプトは次のように実行されます。
sh -c "$(curl -fsSL https://raw.githubusercontent.com/davidgatti/my-development-setup/master/08_Zsh_instead_of_Bash/install.sh)"
sh -x 出力
走れば
sh -cx "$(curl -fsSL https://raw.githubusercontent.com/davidgatti/my-development-setup/master/08_Zsh_instead_of_Bash/install.sh)"
これが出力です。
+ main
+ RED=
+ GREEN=
+ YELLOW=
+ BLUE=
+ BOLD=
+ NORMAL=
+ which tput
+ tput colors
+ ncolors=256
+ [ -t 1 ]
+ [ -n 256 ]
+ [ 256 -ge 8 ]
+ tput setaf 1
+ RED=
+ tput setaf 2
+ GREEN=
+ tput setaf 3
+ YELLOW=
+ tput setaf 4
+ BLUE=
+ tput bold
+ BOLD=
+ tput sgr0
+ NORMAL=
+ set -e
+ printf
+ echo
+ echo ____ __ ___ _____ __
____ __ ___ _____ __
+ echo / __ )____ ______/ /_ |__ \/__ / _____/ /_
/ __ )____ ______/ /_ |__ \/__ / _____/ /_
+ echo / __ / __ `/ ___/ __ \__/ / / / / ___/ __ \
/ __ / __ `/ ___/ __ \__/ / / / / ___/ __ \
+ echo / /_/ / /_/ (__ ) / / / __/ / /__(__ ) / / /
/ /_/ / /_/ (__ ) / / / __/ / /__(__ ) / / /
+ echo /_____/\__,_/____/_/ /_/____/ /____/____/_/ /_/
/_____/\__,_/____/_/ /_/____/ /____/____/_/ /_/
+ echo
+ echo
+ printf
+ wc -l
+ grep /zsh$ /etc/shells
+ CHECK_ZSH_INSTALLED=2
+ [ ! 2 -ge 1 ]
+ unset CHECK_ZSH_INSTALLED
+ rm /home/admin/.zshrc
個人的にcurl
彼が処刑されるとは思わない。
ベストアンサー1
~/.zshrc
ファイルが存在しないため、rm ~/.zshrc
ゼロ以外の値で終了します。rm ~/.zshrc
このコマンドは、関連する長いコマンドのリストの最初のコマンドであるため、次のいずれの&&
コマンドも実行されません。curl
リストの最後のコマンドです。
回避策#1:をrm -f
使用または使用せずに行rm
を終了します&&
。
そして、あなたはset -e
あなたの輝く旗を前に置いた。これにより、予期せず失敗した最初のコマンドでスクリプトが終了します。したがって、削除するだけでは&&
十分ではありません。
解決策#2:回線の使用またはrm -f
終了rm
|| true
|| :
結論:あなたのrm foo 2> /dev/null &&
すべてを変えなさいrm -f foo