2014-10-08 834 views
2

當在shell上手動運行它時工作得很好,但是當我設置一個cronjob在重新啓動時運行它時,我得到「bad variable name」。由cron啓動的bash腳本中的「bad variable name」

#! /bin/sh 
# /etc/init.d/duplicityCleanUp 
export PASSPHRASE=foo 
duplicity remove-older-than 30D --force --gio smb://remote/archiv/ 
duplicity remove-all-but-n-full 1 --force --gio smb://remote/archiv/ 
unset PASSPHRASE 
+0

'#!/bin/sh'有錯誤的空間。它應該是'#!/ bin/sh'。 – fedorqui 2014-10-08 09:37:49

+2

@fedorqui我認爲這個空間太錯了,但顯然它是可以接受的... http://stackoverflow.com/questions/10197690/perl-shebang-space – 2014-10-08 11:00:09

+1

@MarkSetchell有趣!我每天都在這個網站學習東西。非常好知道。 – fedorqui 2014-10-08 11:39:07

回答

7

還有就是#!/bin/sh之間的空間。我不認爲這是報道的問題,但它需要修復

我想你使用的是Unix或Linux版本,其中/bin/sh不是bash,所以 導出語法是錯誤的。

改變你的腳本說

PASSPHRASE=foo 
export PASSPHRASE 

看到這個答案UNIX export command

+0

你可以檢查:「ls -lrt/bin/sh」來查看它是否真的指向bash – user1729564 2016-02-11 09:38:53