Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

atira

macrumors newbie
Original poster
Apr 29, 2013
1
0
Hi

please help me...

I'm trying to run a script written by a friend:

#!/bin/bash

for aStat in ....

do
....
done

when coping the script to the terminal I get:


/bin/bash: Event not found.

for: Command not found.
do: Command not found.

I read the post https://forums.macrumors.com/threads/1072580/
however when coping into terminal:
export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"

I got:
export: Command not found.

what am I doing wrong?

Thanks alot!
 
Hi

please help me...

I'm trying to run a script written by a friend:

#!/bin/bash

for aStat in ....

do
....
done

when coping the script to the terminal I get:


/bin/bash: Event not found.

for: Command not found.
do: Command not found.

I read the post https://forums.macrumors.com/threads/1072580/
however when coping into terminal:
export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"

I got:
export: Command not found.

what am I doing wrong?

Thanks alot!

Let's run a couple of quick tests in terminal.

1) In a fresh new terminal, type "which bash"

It should come back with /bin/bash

#!/bin/bash is the normal start for any script as it starts a new shell to run the rest of the script.

As for your problems with for xx in yy do done, I suggest an sh, csh or bash tutorial, many of which are freely available on the web. The unix command line is powerful but picky. The shell expands * to every file in your current folder, so if you were in a folder full of 99 text files,

for f in *.txt do
cat $f
done

would type out the contents of all 99 files one by one. However the example I'm including here might not work literally as I have typed it. You may need some quotes in there around certain elements to get it to do what you expect.

Here is an example I found near the top googling "for do done":

Code:
#!/bin/bash
for file in /etc/*
do
	if [ "${file}" == "/etc/resolv.conf" ]
	then
		countNameservers=$(grep -c nameserver /etc/resolv.conf)
		echo "Total  ${countNameservers} nameservers defined in ${file}"
		break
	fi
done
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.