gpt4 book ai didi

bash - 案例-意外 token 附近的语法错误

转载 作者:行者123 更新时间:2023-12-03 08:27:19 26 4
gpt4 key购买 nike

运行较大的脚本时出现问题。在中间输出说:

linuxMint_post-install.sh: line 131: syntax error near unexpected token `)'
linuxMint_post-install.sh: line 131: ` "1") echo -e "\e[0;32m you have hdd, skipping to the next step... \e[0m" ;;'

我不希望您将其拖长(脚本数260行),所以我将只发布相关部分:
echo -e "\e[0;32m First we will check if you have ssd or hdd drive \e[0m"
ssd_check="$( cat /sys/block/sda/queue/rotational )"
case "$ssd_check" in
"0") echo -e "\e[0;32m you have ssd drive, so we will optimaze that \e[0m" ;
# noatime
#TODO add noatime automaticly with sed, use code bellow for check (look at I/O scheduler as example)
echo -e "\e[0;32m fstab file will open in xed text editor. Add \"noatime,\" right before \"errors=remount-ro 0 1\" \e[0m" ;
echo -e "\e[0;32m This line has to look like this: \e[0m" ;
echo -e "\e[0;32m UUID=xxxxxxx / ext4 noatime,errors=remount-ro 0 1 \e[0m" ;
echo -e "\e[0;32m When you finish, save file, close text editor and continue \e[0m" ;
gksudo xed /etc/fstab ;
read -n1 -r -p "Press any key to continue..." key ;
# trimming
echo -e "\e[0;32m Now we will change trimming from weekly to daily schedule in cron \e[0m" ;
sudo mv -v /etc/cron.weekly/fstrim /etc/cron.daily ; # if you want to undo this operation simply: sudo mv -v /etc/cron.daily/fstrim /etc/cron.weekly
# swap limit
echo -e "\e[0;32m Now we will chaeck if the swap limit is set to correct value for not overusing SSD \e[0m"
swap_check="$( head -1 /proc/sys/vm/swappiness )"
if [ "$swap_check" -gt 1 ]; then
#MANUAL VERSION v
echo -e "\e[0;32m Swap limit is set to "$swap_check" which is to high. We have to reduce it to 1 \e[0m"
echo -e "\e[0;32m To do so, we will open /proc/sys/vm/swappiness file and please write those two lines at the end of this file: \e[0m"
echo -e "\e[0;32m # Sharply reduce the inclination to swap \e[0m"
echo -e "\e[0;32m vm.swappiness=1 \e[0m"
gksudo xed /proc/sys/vm/swappiness
echo -e "\e[0;32m When you finish, save file, close text editor and continue \e[0m"
read -n1 -r -p "Press any key to continue..." key ;
#AUTOMATIC version - not working! v
#sudo echo "# Sharply reduce the inclination to swap" >> /proc/sys/vm/swappiness #add this lines to reduce swap
#sudo echo "vm.swappiness=1" >> /proc/sys/vm/swappiness
#TODO ^ sudo echo doesn't work, I have tried with command: echo "some text here" | sudo tee -a /proc/.../swappiness with no success to

else
:
fi
# disable hibernation https://sites.google.com/site/easylinuxtipsproject/bugs#TOC-Hibernate-and-suspend-don-t-always-work-well:-they-make-some-computers-malfunction-or-even-enter-a-coma
echo -e "\e[0;32m this step will disable hibernation which will reduce hdd usage, you will be still able to use \"suspend\", \e[0m"
echo -e "\e[0;32m it takes more energy in compare to \"hibernate \", but saves your ssd. You can olways undo this operation later or skip this step \e[0m"
echo -e "\e[0;32m would you like to procede? [y/n] \e[0m"
while read y_n; do
case "$y_n" in
[Yy]* ) sudo mv -v /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla / # com.ubuntu.enable-hibernate.pkla will be moved to / to undo simply move it back again to /etc/polkit-1/localauthority/50-local.d/
echo -e "\e[0;32m hibernation disabled \e[0m" ;;
[Nn]* ) echo -e "\e[0;32m hibernation remains enabled \e[0m";;
*) echo -e "\e[0;31m Wrong input! Type y or n \e[0m" ;
esac
done
# I/O scheduler setting to deadline http://www.techrepublic.com/article/how-to-change-the-linux-io-scheduler-to-fit-your-needs/
echo -e "\e[0;32m First we will check if I/O is already set to \"deadline\" \e[0m"
IO_check="$ ( cat /sys/block/sda/queue/scheduler )" #TODO Make some kind of check if linux is realy installed on sda
case "$IO_check" in
*[deadline]* ) echo -e "\e[0;32m I/O scheduler is already set to \"deadline\", moving to the next step \e[0m";;
*) sudo sed -i 's/\quiet splash\b/& elevator=deadline/' /etc/default/grub ;
sudo update-grub ;
IO_check="$ ( cat /sys/block/sda/queue/scheduler )" #Checking if operation ended propperly
case "$IO_check" in
*[deadline]* ) echo -e "\e[0;32m I/O scheduler has been successfully set to \"deadline\", moving to the next step \e[0m";;
*) echo -e "\e[0;32m I/O something went wrong, please add manually \"elevator=deadline\" right after \"quiet splash\" \e[0m";
echo -e "\e[0;32m It has to look like this: GRUB_CMDLINE_LINUX_DEFAULT=\"quiet splash elevator=deadline\" \e[0m";
gksudo xed /etc/default/grub ;
echo "When you finish, save file, close text editor and continue" ;
read -n1 -r -p "Press any key to continue..." key ;;
esac
esac
"1") echo -e "\e[0;32m you have hdd, skipping to the next step... \e[0m" ;;
*) echo echo -e "\e[0;31m ERROR!!! Wrong output from disc type check \e[0m" ;
esac

输出说这与我的主要情况有关。我不知道这是怎么回事。我试过了“0”和“1”),不带引号,也放在方括号中,但是出现相同的错误。

请帮忙!

最佳答案

更换

"1") echo -e "\e[0;32m you have hdd, skipping to the next step... \e[0m" ;;

通过
     ;;
"1") echo -e "\e[0;32m you have hdd, skipping to the next step... \e[0m" ;;

"0")关闭第一个块。

关于bash - 案例-意外 token 附近的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46856528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com