0
我在运行相当大的脚本时遇到问题。在输出中说:CASE - 意外标记附近的sythax错误
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" ;;'
我不想让你做这lonng(脚本计数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”),并且也括在括号中,但是我得到了同样的错误。
请帮忙!
请参阅关于构建[mcve]的文档。代码样本应该是**最短的代码**测试来生成一个给定的问题。如果您可以删除任何内容并且问题仍然存在,则在提问*之前应该将其删除。 –
(您也可以考虑确保您的代码在http://shellcheck.net/中运行干净,然后再问问题)。 –
神秘的语法错误几乎总是出现在解析器标记的行之前。 – chepner