我试过dos2unix ...没有解决错误
我尝试使用单引号或无引号而不是双引号...没有解决错误
我删除了所有缩进,制表符,空格......没有解决错误
我在每行后添加了分号...没有解决错误
此外,这发生在我完成我的代码(200行长代码)
之前请帮帮我一个?如何删除此错误。
我正在使用bash,ubuntu,sublime-text。
#!/bin/bash
clipboard=$(xclip -selection clipboard -o);
echo $clipboard > savedclip.txt;
echo 'Voice Assistance Started -Panky' | xclip -selection clipboard;
prevclipboard='Voice Assistance Started -Panky';
COUNTER_FILE=counter.txt;
echo 0 > $COUNTER_FILE;
while /bin/true
do
clipboard=$(xclip -selection clipboard -o);
if [ "$prevclipboard" != "$clipboard" ];
then
# Type Command
if [[ "$clipboard" == *type* ]];
then
searchstring=${clipboard/*type/};
echo $searchstring | xclip -selection clipboard;
xdotool type "$searchstring";
searchstring=${clipboard/type*/};
clipboard=$searchstring;
fi &
# File Management Commands
if [[ "$clipboard" == *open*document* ]]||[[ "$clipboard" == *document*open* ]];
then
echo 1 > $COUNTER_FILE;
xdg-open ~/Documents;
fi &
if [[ "$clipboard" == *open*download* ]]||[[ "$clipboard" == *download*open* ]];
then
echo 1 > $COUNTER_FILE;
xdg-open ~/Downloads;
fi &
if [[ "$clipboard" == *open*picture* ]]||[[ "$clipboard" == *picture*open* ]];
then
echo 1 > $COUNTER_FILE;
xdg-open ~/Pictures;
fi &
if [[ "$clipboard" == *open*home* ]]||[[ "$clipboard" == *home*open* ]];
then
echo 1 > $COUNTER_FILE;
xdg-open ~/;
fi &
if [[ "$clipboard" == *open*root* ]]||[[ "$clipboard" == *root*open* ]];
then
echo 1 > $COUNTER_FILE;
xdg-open /;
fi &
if [[ "$clipboard" == *open*video* ]]||[[ "$clipboard" == *video*open* ]];
then
echo 1 > $COUNTER_FILE;
xdg-open ~/Videos;
fi &
# Browser Commands
if [[ "$clipboard" == *google*search* ]];
then
echo 1 > $COUNTER_FILE;
searchstring=${clipboard/*google*search/};
sensible-browser "https://www.google.com/search?q=$searchstring";
else if [[ "$clipboard" == *search*google* ]];
then
echo 1 > $COUNTER_FILE;
searchstring=${clipboard/*search*google/};
sensible-browser "https://www.google.com/search?q=$searchstring";
else if [[ "$clipboard" == *google* ]];
then
echo 1 > $COUNTER_FILE;
sensible-browser 'https://www.google.com/';
fi &
if [[ "$clipboard" == *search*youtube* ]];
then
echo 1 > $COUNTER_FILE;
searchstring=${clipboard/*search*youtube/};
sensible-browser "https://www.youtube.com/results?search_query=$searchstring";
else if [[ "$clipboard" == *you*ube*search* ]];
then
echo 1 > $COUNTER_FILE;
searchstring=${clipboard/*youtube*search/};
sensible-browser "https://www.youtube.com/results?search_query=$searchstring";
else if [[ "$clipboard" == *you*ube* ]];
then
echo 1 > $COUNTER_FILE;
sensible-browser 'https://www.youtube.com/';
fi &
if [[ "$clipboard" == *bing*search* ]];
then
echo 1 > $COUNTER_FILE;
searchstring=${clipboard/*bing*search/};
sensible-browser "https://www.bing.com/search?q=$searchstring";
else if [[ "$clipboard" == *search*bing* ]];
then
echo 1 > $COUNTER_FILE;
searchstring=${clipboard/*search*bing/};
sensible-browser "https://www.bing.com/search?q=$searchstring";
else if [[ "$clipboard" == *bing* ]];
then
echo 1 > $COUNTER_FILE;
sensible-browser 'https://www.bing.com/';
fi &
if [[ "$clipboard" == *duck*go*search* ]];
then
echo 1 > $COUNTER_FILE;
searchstring=${clipboard/*duck*go*search/};
sensible-browser "https://duckduckgo.com/?q=$searchstring";
else if [[ "$clipboard" == *search*duck*go* ]];
then
echo 1 > $COUNTER_FILE;
searchstring=${clipboard/*search*duck*go/};
sensible-browser "https://duckduckgo.com/?q=$searchstring";
else if [[ "$clipboard" == *duck*go* ]];
then
echo 1 > $COUNTER_FILE;
sensible-browser 'https://duckduckgo.com/';
fi &
if [[ "$clipboard" == *news* ]];
then
echo 1 > $COUNTER_FILE;
sensible-browser 'https://tunein.com/radio/NDTV-24X7-s151565/';
fi &
if [[ "$clipboard" == *amazon* ]];
then
echo 1 > $COUNTER_FILE;
sensible-browser 'https://www.amazon.com/';
fi &
if [[ "$clipboard" == *facebook* ]]||[[ "$clipboard" == *face*book* ]];
then
echo 1 > $COUNTER_FILE;
sensible-browser 'https://www.facebook.com/';
fi &
if [[ "$clipboard" == *wikipedia* ]];
then
echo 1 > $COUNTER_FILE;
sensible-browser 'https://www.wikipedia.com/';
fi &
if [[ "$clipboard" == *reddit* ]];
then
echo 1 > $COUNTER_FILE;
sensible-browser 'https://www.reddit.com/';
fi &
if [[ "$clipboard" == *twitter* ]];
then
echo 1 > $COUNTER_FILE;
sensible-browser 'https://www.twitter.com/';
fi &
if [[ "$clipboard" == *inst*gram* ]];
then
echo 1 > $COUNTER_FILE;
sensible-browser 'https://www.instagram.com/';
fi &
# Run Commands & Hotkeys
if [[ "$clipboard" == *open*monitor* ]]||[[ "$clipboard" == *monitor*open* ]]||[[ "$clipboard" == *task*manager* ]];
then
echo 1 > $COUNTER_FILE;
/usr/bin/gnome-system-monitor;
fi &
if [[ "$clipboard" == *open*browser* ]]||[[ "$clipboard" == *browser*open* ]];
then
echo 1 > $COUNTER_FILE;
sensible-browser;
fi &
if [[ "$clipboard" == *open*text*editor* ]]||[[ "$clipboard" == *text*editor*open* ]];
then
echo 1 > $COUNTER_FILE;
subl;
if [ $? != 0 ];
then
gedit;
if [ $? != 0 ];
then
leafpad;
fi &
fi &
fi &
if [[ "$clipboard" == *open*sublime* ]]||[[ "$clipboard" == *sublime*open* ]]||[[ "$clipboard" == *open*sub*lime* ]]||[[ "$clipboard" == *sub*lime*open* ]];
then
echo 1 > $COUNTER_FILE;
subl;
fi &
if [[ "$clipboard" == *open*terminal* ]]||[[ "$clipboard" == *terminal*open* ]]||[[ "$clipboard" == *open*shell* ]]||[[ "$clipboard" == *shell*open* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+alt+t;
fi &
# Window Management Commands
if [[ "$clipboard" == *select*all* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+a;
fi &
if [[ "$clipboard" == *resiz* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key alt+F8;
fi &
if [[ "$clipboard" == *minimiz* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key super+Down;
else if [[ "$clipboard" == *maximiz* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key super+Up;
fi &
if [[ "$clipboard" == *go*back* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key alt+Left;
else if [[ "$clipboard" == *go*forward* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key alt+Right;
fi &
if [[ "$clipboard" == *page*up* ]]||[[ "$clipboard" == *scroll*up* ]]||[[ "$clipboard" == *go*up* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key Page_Up;
else if [[ "$clipboard" == *page*down* ]]||[[ "$clipboard" == *scroll*down* ]]||[[ "$clipboard" == *go*down* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key Page_Down;
fi &
if [[ "$clipboard" == *plac*window*top*left* ]]||[[ "$clipboard" == *mov*window*top*left* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key shift+super+Left;
else if [[ "$clipboard" == *plac*window*top*right* ]]||[[ "$clipboard" == *mov*window*top*right* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key shift+super+Right;
else if [[ "$clipboard" == *plac*window*bottom*left* ]]||[[ "$clipboard" == *mov*window*bottom*left* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+super+Right;
else if [[ "$clipboard" == *plac*window*bottom*right* ]]||[[ "$clipboard" == *mov*window*bottom*right* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+super+Right;
else if [[ "$clipboard" == *plac*window*left* ]]||[[ "$clipboard" == *mov*window*left* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key super+Left;
else if [[ "$clipboard" == *plac*window*right* ]]||[[ "$clipboard" == *mov*window*right* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key super+Right;
fi &
if [[ "$clipboard" == *refresh* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key F5;
fi &
if [[ "$clipboard" == *pan*in* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+alt+Up;
else if [[ "$clipboard" == *pan*out* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+alt+Down;
else if [[ "$clipboard" == *zoom*in* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+plus;
else if [[ "$clipboard" == *zoom*out* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+minus;
else if [[ "$clipboard" == *zoom*default* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+0;
fi &
if [[ "$clipboard" == *decorat*cursor* ]]||[[ "$clipboard" == *cursor*decorat* ]]||[[ "$clipboard" == *highlight*cursor* ]]||[[ "$clipboard" == *cursor*highlight* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key super+k;
fi &
if [[ "$clipboard" == *find* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+f;
fi &
# Miscellaneous
if [[ "$clipboard" == *increas*volume* ]]||[[ "$clipboard" == *volume*increas* ]]||[[ "$clipboard" == *volume*enhanc* ]]||[[ "$clipboard" == *enhanc*volume* ]];
then
echo 1 > $COUNTER_FILE;
amixer -D pulse sset Master 15%+;
pactl set-sink-volume 0 +15%;
else if [[ "$clipboard" == *decreas*volume* ]]||[[ "$clipboard" == *volume*decreas* ]]||[[ "$clipboard" == *reduc*volume* ]]||[[ "$clipboard" == *volume*reduc* ]];
then
echo 1 > $COUNTER_FILE;
amixer -D pulse sset Master 15%-;
pactl set-sink-volume 0 +15%;
else if [[ "$clipboard" == *volume*50* ]]||[[ "$clipboard" == *volume*fifty* ]]||[[ "$clipboard" == *50*volume* ]]||[[ "$clipboard" == *fifty*volume* ]];
then
echo 1 > $COUNTER_FILE;
amixer -D pulse sset Master 50%;
pactl set-sink-volume 0 50%;
else if [[ "$clipboard" == *volume*100* ]]||[[ "$clipboard" == *volume*hundred* ]]||[[ "$clipboard" == *100*volume* ]]||[[ "$clipboard" == *hundred*volume* ]];
then
echo 1 > $COUNTER_FILE;
amixer -D pulse sset Master 100%;
pactl set-sink-volume 0 100%;
else if [[ "$clipboard" == *volume*full* ]]||[[ "$clipboard" == *full*volume* ]];
then
echo 1 > $COUNTER_FILE;
amixer -D pulse sset Master 140%;
pactl set-sink-volume 0 140%;
else if [[ "$clipboard" == *mute* ]];
then
echo 1 > $COUNTER_FILE;
amixer -D pulse sset Master 0;
pactl set-sink-volume 0 0;
fi &
if [[ "$clipboard" == *next*music* ]]||[[ "$clipboard" == *music*next* ]]||[[ "$clipboard" == *next*play* ]]||[[ "$clipboard" == *play*next* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key XF86AudioNext;
else if [[ "$clipboard" == *previous*music* ]]||[[ "$clipboard" == *music*previous* ]]||[[ "$clipboard" == *previous*play* ]]||[[ "$clipboard" == *play*previous* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key XF86AudioPrev;
else if [[ "$clipboard" == *play*music* ]]||[[ "$clipboard" == *music*play* ]]||[[ "$clipboard" == *music*paus* ]]||[[ "$clipboard" == *paus*music* ]]||[[ "$clipboard" == *music*stop* ]]||[[ "$clipboard" == *stop*music* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key XF86AudioPlay;
else if [[ "$clipboard" == *open*music* ]]||[[ "$clipboard" == *music*open* ]];
then
echo 1 > $COUNTER_FILE;
xdg-open ~/Music;
fi &
if [[ "$clipboard" == *clear*screen* ]]||[[ "$clipboard" == *screen*clear* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key alt+super+k;
else if [[ "$clipboard" == *record*screen* ]]||[[ "$clipboard" == *screen*record* ]];
then
echo 1 > $COUNTER_FILE;
ffmpeg -y -f alsa -i default -f x11grab -s 1024x768 -r 30 -i :0.0 -preset ultrafast -acodec aac -strict experimental ~/Videos/recorded.mp4;
else if [[ "$clipboard" == *stop*record*screen* ]]||[[ "$clipboard" == *stop*screen*record* ]]||[[ "$clipboard" == *record*screen*stop* ]]||[[ "$clipboard" == *screen*record*stop* ]];
then
echo 1 > $COUNTER_FILE;
pkill ffmpeg;
else if [[ "$clipboard" == *current*screen*shot* ]]||[[ "$clipboard" == *screen*shot*current* ]]||[[ "$clipboard" == *captur*current* ]]||[[ "$clipboard" == *current*captur* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key alt+Print;
else if [[ "$clipboard" == *screen*shot* ]]||[[ "$clipboard" == *captur*screen* ]]||[[ "$clipboard" == *screen*captur* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key Print;
else if [[ "$clipboard" == *print* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+p;
fi &
# Long Scripts
if [[ "$clipboard" == *updat*computer* ]]||[[ "$clipboard" == *computer*updat* ]]||[[ "$clipboard" == *updat*system* ]]||[[ "$clipboard" == *system*updat* ]]||[[ "$clipboard" == *upgrad*system* ]]||[[ "$clipboard" == *system*upgrad* ]];
then
echo 1 > $COUNTER_FILE;
echo "10<,mmXLSQ" | sudo -S apt-get update;
echo "10<,mmXLSQ" | sudo -S apt-get upgrade -y;
echo "10<,mmXLSQ" | sudo -S apt-get autoremove -y;
echo "10<,mmXLSQ" | sudo -S apt-get autoclean;
echo "10<,mmXLSQ" | sudo -S apt-get clean all;
fi &
# Last Commands
if [[ "$clipboard" == *new*tab* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+t;
else if [[ "$clipboard" == *new*window* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+n;
fi &
if [[ "$clipboard" == *next*tab* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+Tab;
else if [[ "$clipboard" == *previous*tab* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+shift+Tab;
fi &
if [[ "$clipboard" == *next*window* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key alt+Tab;
else if [[ "$clipboard" == *previous*window* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key shift+alt+Tab;
else if [[ "$clipboard" == *switch*window* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key shift+super+w;
fi &
if [[ "$clipboard" == *clos*current*tab* ]]||[[ "$clipboard" == *current*tab*clos* ]]||[[ "$clipboard" == *current*window*clos* ]]||[[ "$clipboard" == *clos*current*window* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key ctrl+w;
else if [[ "$clipboard" == *clos* ]];
then
echo 1 > $COUNTER_FILE;
xdotool key alt+F4;
fi &
# Notify Command Status
count=$(head -c 1 $COUNTER_FILE);
if [ $count -eq '1' ];
then
notify-send "Success" $clipboard; sleep 3; killall notify-osd;
echo 0 > $COUNTER_FILE;
else
notify-send "Failure" $clipboard; sleep 3; killall notify-osd;
fi &
fi &
prevclipboard=$clipboard;
done
答案 0 :(得分:2)
bash中没有else if
构造。相反,您应该使用elif
。
else if [[ "$clipboard" == *search*google* ]];
应该改为
elif [[ "$clipboard" == *search*google* ]];
和其他人一样。自上而下地工作。您稍后看到的错误可能是顶部未解决错误的结果。
作为建议,在调试脚本时,应使用bash -x
来帮助您查明错误。您也可以使用方便的
[shellcheck
]来改进您的脚本。