PDA

View Full Version : [ubuntu] Script won't run



ncc1701e
July 13th, 2009, 02:47 PM
I have written a shell script which executes a bunch of commands including launching an executable in my home directory. So the script looks something like

____________________________________________
#! /bin/sh
command 1
command 2
/home/myhomdirectory/subdirectory/subdirectory/executable -arg1 -arg2 &
Launch Program of Interest
undo command 2
undo command 1
killall -9 executable
____________________________________________

However, the command containing the executable doesn't take effect. If I paste this command alone in to a terminal it works fine. The rest of the scrip seems to run fine.

keplerspeed
July 13th, 2009, 02:50 PM
Add:



#! /bin/bash


At the start of the script and also chmod the script to make it executible.

frunns
July 13th, 2009, 03:06 PM
Add:



#! /bin/bash


At the start of the script and also chmod the script to make it executible.

He already has


# /bin/sh


Don't know if the exclamation mark makes a difference, add it or replace with

#! /bin/bash

ncc1701e
July 13th, 2009, 03:10 PM
oops sorry i actually do have the exclamation in my script I just forgot to type it here I was typing by hand and not pasting. I have edited my original post to reflect this now.

thanks

keplerspeed
July 13th, 2009, 03:14 PM
Have a look here:

http://tldp.org/LDP/abs/html/sha-bang.html


The sha-bang ( #!) [1] at the head of a script tells your system that this file is a set of commands to be fed to the command interpreter indicated. The #! is actually a two-byte [2] magic number, a special marker that designates a file type, or in this case an executable shell script (type man magic for more details on this fascinating topic). Immediately following the sha-bang is a path name. This is the path to the program that interprets the commands in the script, whether it be a shell, a programming language, or a utility. This command interpreter then executes the commands in the script, starting at the top (the line following the sha-bang line), and ignoring comments. [3]

Keith Hedger
July 13th, 2009, 04:32 PM
You should not have a space between the exclamation mark and the path, so:
"#!/bin/bash" NOT "#! /bin/bash" (without the quotes!)