bash script won't execute (Mac)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script won't execute (Mac)
# 1  
Old 03-01-2010
bash script won't execute (Mac)

I can't get any bash scripts to run in Terminal (Mac - Snow Leopard). I have the following super-simple script, and I can't get it to execute despite having the correct permissions (I think).

Code:
#!/bin/bash

echo "WORK... PLEASE?!"

I named the file 'testScript.sh', and I added execution permissions via the following command:

Code:
chmod +x testScript.sh

The permissions look to be correct, but when I type "testScript.sh" I get that stupid
Code:
"-bash: testScript.sh: command not found"

message.

Any idea what I'm doing wrong?
# 2  
Old 03-01-2010
Code:
./testScript.sh

# 3  
Old 03-01-2010
Try
Code:
./testScript.sh

When you type a command, the shell looks in your path, which is a list of directories, for the location of the program. You can find your path by typing "echo $PATH", but it's usually something like /usr/local/bin, /usr/bin and /bin. In this case it didn't find the script in those locations. To run from the current directory, add the "./"
# 4  
Old 03-01-2010
Otherwise,you can also run the script by following command.

sh testscript.sh
# 5  
Old 03-02-2010
Quote:
Originally Posted by rdcwayx
Code:
./testScript.sh

Ah... makes sense. Is there a way to change that (or would it be best to leave it alone)?

Thanks for all the quick responses. You guys/gals are awesome!
# 6  
Old 03-02-2010
Depend on which default shell you use.

Add below line in your .profile

Code:
PATH=$PATH:.
export PATH

After that, you can run with filename directly.

Last edited by rdcwayx; 03-02-2010 at 01:52 AM..
# 7  
Old 03-02-2010
You can use the following way also to run the bash script

Code:
. script_name.sh

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script won't run because hardware won't produce display

Can anyone offer any advice on how to modify the script below to work on a new system we have, that has no graphics capability? We admin the system through a serial RAS device. I've tried running the below script through the RAS and through an ssh -X session. It failed with something like "GTK... (3 Replies)
Discussion started by: yelirt5
3 Replies

2. Shell Programming and Scripting

Nested double quotes won't work in my bash script?

In a bash script I have: LSCMD="find /project/media/ -mindepth 2 -maxdepth 2 -name \"files*pkg\"" ALL_PACKAGES=$( $LSCMD | sort 2>/dev/null) But I get nothing returned. It's just all blank. If I run the find command in a terminal, I get dozens of hits. I figure it's the way how I'm... (3 Replies)
Discussion started by: superbbrr
3 Replies

3. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

4. UNIX for Dummies Questions & Answers

Bash script to execute a program to rename files

I just can't figure it out , so please just give me a pice of advise how to: The existing Linux program foo2bar takes as its only argument the name of a single foo file and converts it to an appropriately-named bar file. Provide a script that when executed will run foo2bar against all foo... (4 Replies)
Discussion started by: raymen
4 Replies

5. Shell Programming and Scripting

How to execute a bash script

Hi All, I am trying to write a simple bash script. rm -f File1 I saved this as test.sh Now when I want to execute it, I type ./test.sh It gives me error "command not found" What I am doing incorrect here? Do I have to add anything in script like #!/bin/bash (5 Replies)
Discussion started by: palak08
5 Replies

6. Shell Programming and Scripting

Execute ssh commands through bash script

Hi all! I am trying to write a script that will check if a certain directory is available at several different nodes and then do stuff in it ..... On the beginning of the script I give as a variable the directory and the number of the nodes and then I loop like this: for... (3 Replies)
Discussion started by: idet2
3 Replies

7. OS X (Apple)

Why won't the at command work in Mac OS X?

I typed: echo "echo hi > at_log.txt" | at now +1minute to test the at command on my terminal. I got the message: job 8 at Thu Feb 25 18:42:00 2010 I waited for a minute but nothing happened. I tried listing at_log.txt, but it said there was no such file. Am I doing something... (2 Replies)
Discussion started by: Ultrix
2 Replies

8. UNIX for Dummies Questions & Answers

how to execute sh script in bash shell via crontab

hello. we are porting over from HPUX Shell to Linux. my default shell is bash so i can no longer schedule to execute a sh script in crontab. can anyone pls help me out? I searched the site but didnt find any details. thanks! (1 Reply)
Discussion started by: jigarlakhani
1 Replies

9. Shell Programming and Scripting

loop does not execute in bash script?

I have a very basic bash shell script, which has many "while... done; for .... done" loop clauses, like the following ~~ #!/bin/bash while blablalba; do .... done < /tmp/file for line in `cat blablabla`; do grep $line /tmp/raw ; done > /tmp/1; while blablalba2; do .... done <... (2 Replies)
Discussion started by: fedora
2 Replies
Login or Register to Ask a Question