我正在尝试创建一个脚本来启动一些程序
启动文件
knetworkmanager
emesene
keepassx
Run Code Online (Sandbox Code Playgroud)
问题是当我运行脚本时,它只启动 knetworkmanager。这是因为它会启动它,然后等到它完成。如何在不等待的情况下启动程序?我不认为我可以在每个命令后添加“&”,因为脚本完成后所有进程仍将被终止。
问题与 .shell 脚本有关bash。
如何使用脚本检查当前目录中的哪些文件是软链接?
如果我使用了错误的术语,当我说soft links 时,我指的是使用ln -s.
我唯一能想到的是ls -la作为一个表达式进行评估,并解析它的结果,但这显然不是最好的解决方案。
我写了一个脚本。当它启动时,它不会停止,它会不断从 Internet 获取数据。我可以这样称呼它:
cd /User/Desktop/project/internetScanner/
python3 main.py start
Run Code Online (Sandbox Code Playgroud)
但我想直接从终端这样调用它,在目的地内:
internetScanner start
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做?
我想要一个 shell 脚本方法来测试/报告是否安装了软件包。我不需要细节,只需要布尔返回来设置逻辑流程。我查看了Find if a package is installed,但dpkg返回复杂的输出,其格式会根据软件包是在 Debian 存储库中还是在 Ubuntu PPA 中而发生变化。
我发现这apt-cache做得很好,我想出了这个方法:
is_installed=0
test_installed=( `apt-cache policy package-name | grep "Installed:" ` )
[ ! "${test_installed[1]}" == "(none)" ] && is_installed=1
Run Code Online (Sandbox Code Playgroud)
有谁知道更简单或更直接的方法?
我正在尝试生成一个基于 Applescript 的 shell 命令,该命令告诉 Mac OS X 中的预览应用程序关闭特定窗口。
#!/bin/sh
osascript <<EOF
tell application "Preview"
close "$1"
end tell
EOF
Run Code Online (Sandbox Code Playgroud)
但这不起作用:我收到错误消息
25:52: execution error: Preview got an error: "musixdoc.pdf" doesn’t understand the close message. (-1708)
Run Code Online (Sandbox Code Playgroud)
如果 shell 函数需要特定的 -e/+e 设置才能工作,是否可以在本地设置该设置,然后在退出该函数之前将其恢复到以前的设置?
myfunction()
{
# Query here if -e is set and remember in a variable?
# Or push the settings to then pop at the end of the function?
set +e
dosomething
doanotherthing
# Restore -e/+e as appropriate, don't just do unconditional set -e
}
Run Code Online (Sandbox Code Playgroud) [[ condition ]]使用and[ condition ]或(( condition ))and有什么区别( condition )?在什么场景下我们需要使用这两者?
(( 10 > 9 ))有效但(( 10 -gt 9 ))无效[[ 10 -gt 9 ]]有效但[[ 10 > 9 ]]无效如何删除以-pbash命名的文件?尝试rm "-p"抱怨 -p 不是一个有效的论点。
自动重新连接交互式 SSH 会话以在终端上重新建立 shell 的最佳方法是什么?我查看了 autossh,但这似乎专用于端口转发(我不需要)。
有没有任何 shell-fu 或实用程序允许这样做?
举个例子:
List="A B C D"
for I in $List
do
OUT=$OUT" -$I"
done
Run Code Online (Sandbox Code Playgroud)
当我运行它时,结果是:
" -A -B -C -D"
Run Code Online (Sandbox Code Playgroud)
但希望它是:
"-A -B -C -D"
Run Code Online (Sandbox Code Playgroud)
如何在没有前导空格的情况下进行连接?
顺便说一句,这是脚本的参数列表。