我创建了一个自定义的bashrc脚本,无法让它运行。 Bash不报告bash: /home/chronos/user/.bashrc: line 166: syntax error: unexpected end of file
以外的任何内容。我已经检查了函数中缺少的括号和缺少的endqoutes,就我所知,这是导致这种情况的两件大事。
# /etc/skel/.bashrc
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output. So make sure this doesn't display
# anything or bad things will happen !
# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
envdir="~/Downloads"
###########################
# Put your fun stuff here.#
###########################
#clear terminal screen to set the stage.
clear
######################################
#configuration for greeting
#setup script.
echo "v 11"
sleep 1s
if [ -e ~/kv-bash ]
then
cd ~/
source ./kv-bash
else
cd ~/
wget --no-cache https://github.com/damphat/kv-bash/raw/master/kv-bash
source ~/.bashrc
fi
source ./kv-bash
uname=""
#message 3
msg3="Use startenv or runenv to start a crouton enviroment"
#message 2
msg2="run 'commands' to view extra commands. run setname to set a name"
#message 1
msg1="Welcome to BASH! This bash welcome tweak is made by Raymond Dean "
#message 4
msg4="This-chromebook-is-property-of-$uname "
#message 5
msg5="Battery is $(cat /sys/class/power_supply/BAT0/status). Battery capacity is $(cat /sys/class/power_supply/BAT0/capacity)% [AT TIME OF LOGIN]"
#message 6
msg6="run 'update' to update .bashrc. Use 'setenv' to configure claunch"
######################################################################
#aliases and funcrtions
alias enter-chroot="sudo sh '/media/removable/crouton/bin/enter-chroot'"
alias crouton="sudo sh '/media/removable/crouton/crouton'"
alias installkali="crouton -r kali-rolling -t xfce,xiwi -p/media/removable/crouton"
alias installxenial="crouton -r xenial -t lxde,xiwi -p /media/removable/crouton"
alias runenv="startenv"
alias set="kvset"
alias setname="kvset uname"
update() {
cd ~/
mv ~/.bashrc ~/.bashrc.bak
wget --no-cache https://github.com/pcs3rd/Expandablebash/raw/master/.bashrc > /dev/null
echo "installed!"
source ~/.bashrc
}
startenv() {
if [ -e ~/kv-bash ]
then
echo "type enviroment to launch"
echo "$env1n, $env2n, $env3n"
read launchenv
if [ "$launchenv" == "$env1n" ]; then
sudo sh $env1
fi
if [ "$launchenv" == "$env2n" ]; then
sudo sh $env2
fi
if [ "$launchenv" == "$env3n" ]; then
sudo sh $env3
fi
else
setenv
fi
}
setenv() {
echo "where is the crouton chroots folder?"
read envdir
sleep 1s
echo "type path to script to start enviroment 1"
read env1
sleep 1s
echo "what is the name of this enviroment?"
read env1n
sleep 1s
echo "type path to script to start enviroment 2"
read env2
sleep 1s
echo "what is the name of this enviroment?"
read env2n
sleep 1s
echo "type path to script to start enviroment 3"
read env3
sleep 1s
echo "what is the name of the enviroment?"
read env3n
echo "done"
kvset env1 $env1
kvset env2 $env2
kvset env3 $env3
kvset env3n $env3n
kvset env2n $env2n
kvset env1n $env1n
kvset envdir $envdir
kvset setup 1
}
todo() {
echo "add custom greeter messages through 'setup', auto checking for ubpdates at start & auto-rollback for failed updates and add many more commands [tools]"
}
#extra help prompt
commands() {
echo "use 'set env[number 1-3]n [enviroment name]' to change the name shown for a script"
echo "use 'set env[number 1-3] [path to script]' to change path to script quickly"
echo "use 'set uname [insert username here]' to change username shown"
echo "enter-chroot opens a terminal with crouton"
echo "crouton is a chroot enviroment tool"
echo "installkali installs kali linux"
echo "installxenial installs ubuntu xenial"
echo "use 'top' to manage tasks"
echo "use 'update' to update your ~/.bashrc file"
echo "use 'setup' to configure extra options"
echo "use 'setname' to set a name"
echo "use setenv to set crouton launcher script variables"
echo "use startenv to start a crouton enviroment"
echo "use 'todo' to check a bad todo list"
}
#allows creation of banners
banner() {
msg=". $* ."
edge=$(echo "$msg" | sed 's/././g')
echo -e "\e[96m$edge\e[0m"
echo -e "\e[96m$msg\e[0m"
echo -e "\e[96m$edge\e[0m"
}
###############################################################################
banner "$msg1"
banner "$msg2"
banner "$msg3"
banner "$msg4"
banner "$msg5"
banner "$msg6"
echo -e "\e[96mthe current chroots are:\e[0m"
echo -e "\e[96m$(ls -x $envdir)\e[0m"
echo hi
答案 0 :(得分:1)
Shell Check报告:
Line 12:
if [[ $- != *i* ]] ; then
^-- SC1046: Couldn't find 'fi' for this 'if'.
^-- SC1073: Couldn't parse this if expression. Fix to allow more checks.
Line 166:
^-- SC1047: Expected 'fi' matching previously mentioned 'if'.
^-- SC1072: Expected 'fi'. Fix any mentioned problems and try again.