Boards.ie uses cookies. By continuing to browse this site you are agreeing to our use of cookies. Click here to find out more x
Post Reply  
 
Thread Tools Search this Thread
19-02-2003, 14:01   #1
b3t4
Registered User
 
Join Date: Dec 2002
Posts: 1,253
Running shell scripts??

hey ppl,

(im new to all this mac osx lark)

Well iv written a shell script using BBEdit, thing is iv no idea what to do with it
now. Iv been trying to get it to run using the run menu option in the #! drop down menu but it doesnt appear to do anything. I try the "run in terminal" option
and that gives me an error (61).

Iv checked the commands iv written into the script to see if it was those causing the problem but it doesnt appear to be that either.

Iv saved the file as a .sh file and chmod +x on it but Im still baffled.

Iv been googling and cannot find a decent page written about how to write shell
scripts, ye know of any??

Any ideas??
A.
b3t4 is offline  
Advertisement
19-02-2003, 14:06   #2
Dr_Teeth
Registered User
 
Dr_Teeth's Avatar
 
Join Date: Feb 1998
Posts: 1,968
Why don't you just open up a terminal window, cd to where you've saved the script and go ./scriptname.sh ?

Teeth.
Dr_Teeth is offline  
19-02-2003, 14:16   #3
b3t4
Registered User
 
Join Date: Dec 2002
Posts: 1,253
Yup Teeth hav tried that.

It says command not found??
Is there something that i need to do.

The script im testing this with is the following

#!/bin/tcsh
mkdir /Users/Shared/FlatFiles

Sorry if these are stupid questions.

A
b3t4 is offline  
19-02-2003, 14:24   #4
b3t4
Registered User
 
Join Date: Dec 2002
Posts: 1,253
Rite I found the problem.

It dont appear that I can trust older people with some stuff.

It shud be #!/bin/bash (doh!)

Thanks,
A.
b3t4 is offline  
19-02-2003, 14:30   #5
Dr_Teeth
Registered User
 
Dr_Teeth's Avatar
 
Join Date: Feb 1998
Posts: 1,968
Indeed.

Teeth.
Dr_Teeth is offline  
Advertisement
19-02-2003, 17:07   #6
b3t4
Registered User
 
Join Date: Dec 2002
Posts: 1,253
Hmmm well i did say the prob was fixed but iv run into another one and cannot
see why the following is happening.

I have a couple of scripts written so far all of which work except for one.
The one that isnt working is baffling me. It appears to be messing bout with
the shebang line(learned something new today ). It can complete "/bin/bas"
but spits out odd ASCII characters and then the "h" therefore it doesnt
understand the command and ends before completing the script... This script is
working fine until I want to run it in the terminal.

Any ideas??
A.
b3t4 is offline  
19-02-2003, 18:20   #7
Dr_Teeth
Registered User
 
Dr_Teeth's Avatar
 
Join Date: Feb 1998
Posts: 1,968
Could be a hidden char there that's messing things up. Try having a look at the script from inside the terminal - use 'cat scriptname.sh' and see if what comes out is correct.

Teeth.
Dr_Teeth is offline  
20-02-2003, 09:09   #8
b3t4
Registered User
 
Join Date: Dec 2002
Posts: 1,253
I thought that as well Teeth. So I went along and copied the shebang line from
the scripts that are working, that didnt work so I thought maybe the copy had a hidden char. So I then rewrote the shebang line. Saving all the way and testing to
see if it was working. Still no joy.

I tried the cat command on the file, as you suggested and it shows everything
but the shebang line!!!! bit odd

Iv compared the working scripts to the one not working and I cannot see any
difference.

A.
b3t4 is offline  
20-02-2003, 10:31   #9
Dr_Teeth
Registered User
 
Dr_Teeth's Avatar
 
Join Date: Feb 1998
Posts: 1,968
Weird.. try editing the script using a editor like pico or vi, to see if your gui editor is doing strange things. 'cat' should display everything in the file, if the shebang line is missing from its output then something is wrong somewhere.

Teeth.
Dr_Teeth is offline  
Advertisement
20-02-2003, 10:50   #10
b3t4
Registered User
 
Join Date: Dec 2002
Posts: 1,253
It appears that the editor was the problem from the very start.

#!/bin/bash and #!/bin/tcsh both work.

Don't think Il be using BBEdit again.

Thanks for your help,
Much appreciated,
A.
b3t4 is offline  
22-02-2003, 01:38   #11
timod
Registered User
 
timod's Avatar
 
Join Date: May 2001
Location: Cork
Posts: 398
The problem is that BBedit can create 3 different type of text file (well not really a problem - it's exellent!)

Windows/Mac/Unix use different encodings for line termination.

To mark the end of a line in a text file the MacOS uses a carriage return (CR, ASCII 13), UNIX uses a line feed (LF, ASCII 10) while Windows uses a carriage return and a line feed (CRLF).

When you wrote your initial script, the shell probably saw everything on the one line.

In the bbedit window, there is a row of icons on top... the one that looks like a page, click it, and choose unix.
Should do the trick for shell scripts.

BBedit is excellent
timod is offline  
Post Reply

Quick Reply
Message:
Remove Text Formatting
Bold
Italic
Underline

Insert Image
Wrap [QUOTE] tags around selected text
 
Decrease Size
Increase Size
Please sign up or log in to join the discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search