Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to run dpkg without shell?

Here is my problem:

I made and script in my USB key.

To run this script, I created rules in /etc/udev/rules/49-usb-rules:

SUBSYSTEM=="block", KERNEL=="sd*1", ACTION=="add", RUN+="/bin/sh /opt/local/ %E{ID_FS_LABEL} %E{ID_FS_UUID}"

/opt/local/ calls my located on my USB key.

It works well, but in that script, I try to run dpkg -i to install a Debian archive and it fails.

After some research, I tried to run:

at -f /media/usb-key/ -v 12:00

And i had the same problem.

So I saw that dpkg seems to need a shell to be run.

I tried `dpkg-reconfigure --frontend=dialog debconf`` and set up non-interactive, but it didn't seems to work neither.

How can I run dpkg -i from my script?

Here is my (on the usb key):


touch /tmp/fic

echo "Installation du firmware" > /tmp/fic

DIR=$( readlink -f "$( dirname "$0" )")

export PATH=$PATH

/usr/bin/dpkg -i --force-all $DIR/radiolive.deb >> /tmp/fic 2>&1

echo "FIN" >> /tmp/fic

Here is my (on my hard-drive):


 autorun() {
 if [ -z ${1} ]; then

 sleep 10

  if [ -f ${FILE} ]; then
    /bin/bash ${FILE}

 autorun $@ &
share|improve this question
(1) As far as I know, you need administrator privileges to run dpkg -i and install a package. You should use gksu. (2) Have you made the file executable (chmod +x)? (3) Have you added the #!/bin/sh or #!/bin/bash on top of the file? (4) It would help if you post the contents of the script. – medigeek Jul 5 '12 at 11:54
@medigeek gksu is graphical, and will fail if run in the background like this. Since dpkg is a non-graphical program, it can simply be run with sudo. (But if the script is itself running as root, then of course neither is necessary.) – Eliah Kagan Jul 5 '12 at 11:56
udev is run as root. In my i create the file: "-rw-r--r-- 1 root root 317 5 juil. 14:02 /tmp/fic". So this script is well executed and with the good privileges. But thank's for your answer. My script has the shebang #!/bin/sh – Korigan Jul 5 '12 at 12:09
${BASH_SOURCE[0]} is not supported in sh, but then again you run the file with /bin/bash in the usb_autorun script so that should work in theory... Try using #!/bin/bash shebang on both autorun and usb_autorun -- is there any output in /tmp/fic ? – medigeek Jul 5 '12 at 18:04
up vote 1 down vote accepted

I think your problem is this line:

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

BASH_SOURCE is a "bad substitution" for sh.

On the other hand, I found this:

udev does not run these programs on any active terminal, and it does not execute them under the context of a shell. Be sure to ensure your program is marked executable, if it is a shell script ensure it starts with an appropriate shebang (e.g. #!/bin/sh), and do not expect any standard output to appear on your terminal.

So basically the problems could be:

a) You're not using a shebang for the and you need to add #!/bin/bash to both and

b) try this line instead and use #!/bin/sh on both and

DIR=$( readlink -f "$( dirname "$0" )")

Note: This solution is a bit unsafe (Anyone can run anything in and get it executed), but on a local basis I believe it's harmless. Nevertheless, I would use some other name instead of "", such as "" -- just to avoid any malware scripts.

share|improve this answer
Thank's a lot! You were right! All is working well now! For the malware you are right, i will rename my Thank's medigeek! I also had to add "export PATH" before dpkg instruction for this to work but now it's ok! – Korigan Jul 6 '12 at 12:51
I also had to edit my rules and give him a numer greater than 49 to be sure to be execute. – Korigan Jul 6 '12 at 13:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.