运行bash脚本时出现奇怪的问题

发布于 2024-10-25 19:25:52 字数 1074 浏览 1 评论 0原文

我编写了一个从网站获取歌词的 bash 脚本。脚本在这里--> http://scrippets.wordpress。 com/2011/02/01/fetching-lyrics-of-songs-from-the-terminal/(脚本中的缩进是正确的,与博客上的样子不同) 从终端执行该脚本时效果非常好。现在,我使用 compiz 命令创建了一个自定义键盘快捷键,按下正确的组合键时会执行以下命令:

gnome-terminal --working-directory="/home/tapan/sandbox/bash/" --window-with-profile=lyrics -e "/home/tapan/sandbox/bash/lyrics.sh" -t "`rhythmbox-client --print-playing`"

我创建了一个名为“lyrics”的新配置文件,为打开自定义外观的终端提供支持。当我使用此配置文件打开终端并运行脚本时,它再次完美运行。但是,当我使用键盘快捷键运行自定义命令时,出现以下错误:

Pink Floyd - Is There Anybody Out There?
wget: missing URL
Usage: wget [OPTION]... [URL]...

Try `wget --help' for more options.
cat: 3.txt: No such file or directory

我无法弄清楚出了什么问题。我的意思是,如果它通常在终端中工作得很好,为什么它不能工作呢?有什么建议吗? PS:我写的脚本非常初级和新手,所以任何改进它的建议也欢迎在评论中:)

编辑:输出发生了一些变化,现在它只显示正在播放的歌曲的名称,没有其他内容。虽然有时它仍然显示 wget 错误。

EDIT2:当我从终端运行 gnome 终端命令时,它可以工作。仅当使用 compiz 命令通过键盘快捷键运行它或使用运行对话框(alt+f2 )时才会出现问题。

I wrote a bash script that fetches lyrics from a website. The script is here --> http://scrippets.wordpress.com/2011/02/01/fetching-lyrics-of-songs-from-the-terminal/ (the indentations in the script are correct unlike how it looks on the blog)
This script works perfectly well when executed from the terminal. Now i created a custom keyboard shortcut using compiz commands, that executes the following command when the right key combination is pressed :

gnome-terminal --working-directory="/home/tapan/sandbox/bash/" --window-with-profile=lyrics -e "/home/tapan/sandbox/bash/lyrics.sh" -t "`rhythmbox-client --print-playing`"

I created a new profile called "lyrics" to give the terminal that opens up a custom look. When i open up a terminal with this profile and run the script, it works perfectly fine again. However, when i use the keyboard shortcut to run the custom command, i get the following error:

Pink Floyd - Is There Anybody Out There?
wget: missing URL
Usage: wget [OPTION]... [URL]...

Try `wget --help' for more options.
cat: 3.txt: No such file or directory

I cannot figure out whats wrong. I mean if it works perfectly well in the terminal normally, why shouldn't this work? Any suggestions?
PS: The script i have written is pretty elementary and noobish, so any suggestions to improve it are also welcome in the comments :)

EDIT: The output has changed a little, now it just shows the name of the song playing and nothing else. Though sometimes it still shows the wget error.

EDIT2: When i run that gnome terminal command from a terminal, it works. The problem is only when running it with the keyboard shortcut using compiz commands or if i use the run dialog (the alt+f2 one).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乖乖哒 2024-11-01 19:25:52

这两个 wget 命令可能应该将 url 变量放在双引号中,例如: wget -q -U Mozilla -O 1.txt $link 应该是 wget -q -U Mozilla -O 1.txt“$link”

The two wget commands should probably have the url variables in double quotes, for example: wget -q -U Mozilla -O 1.txt $link should be wget -q -U Mozilla -O 1.txt "$link"

昨迟人 2024-11-01 19:25:52

您需要对歌曲标题进行 uriencode,以便“?”、“&”、“%”和“+”等特殊字符不会按字面意思传递到您的 URL 中。

name3=${name2//\?/%3F}
searchq=${name3// /+}

将处理 ? 的。我不知道 bash 中是否有更通用的解决方案,无需求助于单行 Perl 或 Python 脚本。

You need to uriencode your song title so that special characters like '?', '&', '%', and '+' are not passed literally in your URL.

name3=${name2//\?/%3F}
searchq=${name3// /+}

will handle the ?'s. I don't know of a more general solution in bash without resorting to one-line Perl or Python scripts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文