我正在研究脚本在从Debian存档(.deb)文件解压缩该包之前执行的这个preinst文件的内容.
该脚本具有以下代码:
#!/bin/bash
set -e
# Automatically added by dh_installinit
if [ "$1" = install ]; then
if [ -d /usr/share/MyApplicationName ]; then
echo "MyApplicationName is just installed"
return 1
fi
rm -Rf $HOME/.config/nautilus-actions/nautilus-actions.conf
rm -Rf $HOME/.local/share/file-manager/actions/*
fi
# End automatically added section
Run Code Online (Sandbox Code Playgroud)
我的第一个问题是关于这一行:
set -e
Run Code Online (Sandbox Code Playgroud)
我认为脚本的其余部分非常简单:它检查Debian/Ubuntu包管理器是否正在执行安装操作.如果是,它会检查我的应用程序是否刚刚安装在系统上.如果有,脚本将打印消息"MyApplicationName刚刚安装"并结束(return 1
意味着以"错误"结束,不是吗?).
如果用户要求Debian/Ubuntu软件包系统安装我的软件包,该脚本还会删除两个目录.
这是对的还是我错过了什么?
我正在研究Ubuntu系统,目前这正是我正在做的事情:
if ! which command > /dev/null; then
echo -e "Command not found! Install? (y/n) \c"
read
if "$REPLY" = "y"; then
sudo apt-get install command
fi
fi
Run Code Online (Sandbox Code Playgroud)
这是大多数人会这样做的吗?还是有更优雅的解决方案?
我正在编写我的第一个shell脚本.在我的脚本中,我想检查是否存在某个命令,如果不存在,则安装可执行文件.我该如何检查此命令是否存在?
if #check that foobar command doesnt exist
then
#now install foobar
fi
Run Code Online (Sandbox Code Playgroud) 在bash脚本中,我需要启动用户Web浏览器.似乎有很多方法可以做到这一点:
$BROWSER
xdg-open
gnome-open
在GNOME上www-browser
x-www-browser
在大多数平台上是否有更多标准而非其他方式来实现这一点,或者我应该采用以下方式:
#/usr/bin/env bash
if [ -n $BROWSER ]; then
$BROWSER 'http://wwww.google.com'
elif which xdg-open > /dev/null; then
xdg-open 'http://wwww.google.com'
elif which gnome-open > /dev/null; then
gnome-open 'http://wwww.google.com'
# elif bla bla bla...
else
echo "Could not detect the web browser to use."
fi
Run Code Online (Sandbox Code Playgroud) 我需要通过运行which abc
命令来设置环境.是否有Python等效的which
命令功能?这是我的代码.
cmd = ["which","abc"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
res = p.stdout.readlines()
if len(res) == 0: return False
return True
Run Code Online (Sandbox Code Playgroud) 我想知道什么是检查一个程序是否可以执行bash而不执行它的最简单方法?它至少应检查文件是否具有执行权限,并且具有相同的体系结构(例如,不是Windows可执行文件或其他不支持的体系结构,如果系统是32位,则不是64位,......)作为当前系统.
如何从python脚本检查程序是否存在?
比方说,你要检查wget
或curl
可用.我们假设他们应该走在路上.
看到多平台解决方案是最好的,但目前Linux已经足够了.
提示:
--version
.此外,我会感谢一个更通用的解决方案,比如 is_tool(name)
如果在Linux上安装了PostgreSQL,我想检查脚本并打印结果.有关如何进行检查的任何建议?
我在php中需要这样的东西:
If (!command_exists('makemiracle')) {
print 'no miracles';
return FALSE;
}
else {
// safely call the command knowing that it exists in the host system
shell_exec('makemiracle');
}
Run Code Online (Sandbox Code Playgroud)
有什么解决方案吗?