我设法在我正在处理的init脚本中跟踪完成了一个奇怪的问题.我在以下示例中简化了问题:
> set -x # <--- Make Bash show the commands it runs
> cmd="echo \"hello this is a test\""
+ cmd='echo "hello this is a test"'
> $cmd
+ echo '"hello' this is a 'test"' # <--- Where have the single quotes come from?
"hello this is a test"
Run Code Online (Sandbox Code Playgroud)
为什么bash将这些额外的单引号插入到执行的命令中?
额外的引号在上面的例子中没有引起任何问题,但它们真的让我头疼.
对于好奇,实际的问题代码是:
cmd="start-stop-daemon --start $DAEMON_OPTS \
--quiet \
--oknodo \
--background \
--make-pidfile \
$* \
--pidfile $CELERYD_PID_FILE
--exec /bin/su -- -c \"$CELERYD $CELERYD_OPTS\" - $CELERYD_USER"
Run Code Online (Sandbox Code Playgroud)
产生这个:
start-stop-daemon --start …Run Code Online (Sandbox Code Playgroud) 我在GitHub存储库中有许多python包,在PyPi中提供这些包非常棒.我知道我可以手动执行这些版本(更新版本号,可能更新更改日志,在GitHub中标记发行版,从GitHub获取下载URL,使用发布更新PyPi等)但我一直认为必须有脚本/ utility在某处使这个单命令进程.
我对python包装过程并不熟悉,所以也许我是从错误的角度来看这个.我只是觉得我不能成为第一个想让整个过程变得容易的人.
编辑:因为我要求的内容似乎有些混乱:是否有任何工具可以使PyPi的Python包更快更简化?
我试过四处寻找但还没找到任何东西.
我需要使用bash将一行插入到python文件中.此行需要在文件中的任何初始注释后出现.
所以给定文件:
#!/usr/bin/python
# This is just
# an example comment
moo = "cow"
... etc ...
Run Code Online (Sandbox Code Playgroud)
我需要一个bash命令来插入一个这样的新行:
#!/usr/bin/python
# This is just
# an example comment
NEW LINE GOES HERE
moo = "cow"
... etc ...
Run Code Online (Sandbox Code Playgroud)
我完全不知道如何做到这一点.我已经尝试逐行循环遍历文件,但这最终变得非常可怕并严重搞乱了文件的空白.
任何建议都会很棒!
亚当
PS.是的,这有点奇怪,它是一个持续集成构建脚本的一部分.
编辑
为了记录,我尝试的代码是:
insert_setup_code() {
installed=false
tmpfile="/tmp/$RANDOM"
cat "$INSTALL_TO" | while read -d \n l; do
echo "$l" >> $tmpfile
if [[ ! $installed && ! `echo "$l" | grep "^#"` ]]; then
echo "LINE OF CODE HERE" >> $tmpfile …Run Code Online (Sandbox Code Playgroud)