Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | More sites on tool bar ?

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion
Register FAQ Community Calendar

$ bash myscript
Reply
 
Thread Tools
Old 30-10-2006, 12:00   #1
altis
Inactive
 
altis's Avatar
 
Join Date: Jun 2003
Location: Warrington ntl:81304 Altitude: 12m (and falling)
Posts: 4,499
altis has a nice shiny staraltis has a nice shiny star
altis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny star
$ bash myscript

I'm having problems running scripts on CentOS 4.4.

I have a script file called wait.txt that looks like this:
Code:
sleep 10s
echo "Hello World"
All very simple!

But when I try to run the thing I get this:
Code:
[root@localhost asterisk]# cat wait.txt
sleep 10s
echo "Hello World"[root@localhost asterisk]# bash wait.txt
'leep: invalid time interval `10s
Try `sleep --help' for more information.
Hello World
[root@localhost asterisk]#
Eh!
altis is offline   Reply With Quote
Advertisement
Old 30-10-2006, 12:04   #2
gazzae
Inactive
 
gazzae's Avatar
 
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
Re: $ bash myscript

Try taking the s out so the line is just

Sleep 10
gazzae is offline   Reply With Quote
Old 30-10-2006, 12:13   #3
altis
Inactive
 
altis's Avatar
 
Join Date: Jun 2003
Location: Warrington ntl:81304 Altitude: 12m (and falling)
Posts: 4,499
altis has a nice shiny staraltis has a nice shiny star
altis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny star
Re: $ bash myscript

Code:
[root@localhost asterisk]# cat wait.txt
sleep 10
echo "Hello World"[root@localhost asterisk]# bash wait.txt
'leep: invalid time interval `10
Try `sleep --help' for more information.
Hello World
[root@localhost asterisk]#
altis is offline   Reply With Quote
Old 30-10-2006, 12:23   #4
The Jackal
Inactive
 
Join Date: Oct 2006
Posts: 1,604
The Jackal has a bronzed appealThe Jackal has a bronzed appeal
The Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appeal
Re: $ bash myscript

COME ON BOYS stop dissing me ....

wait.sh

------------------------------------------
#!/bin/sh

echo "Hello World"
echo "Going to sleep"
sleep 3;
echo "Wakey wakey"
------------------------------------------

chmod 755 wait.sh

./wait.sh ( to execute)

---------------------
EDIT
Notice the first line of the script ?
#!/bin/sh

?

That tells the OS that this is a shell script...

If I were to change this line to #!/usr/bin/perl
it would become a perl script
The Jackal is offline   Reply With Quote
Old 30-10-2006, 12:40   #5
altis
Inactive
 
altis's Avatar
 
Join Date: Jun 2003
Location: Warrington ntl:81304 Altitude: 12m (and falling)
Posts: 4,499
altis has a nice shiny staraltis has a nice shiny star
altis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny staraltis has a nice shiny star
Re: $ bash myscript

I don't know why Linux peeps like to make life so hard for themselves. There are at least two ways to run a script. As you say, you can add '#!/usr/bin... etc' at the front, then chmod it to make it executable and the run it with './scriptname'. Alternatively, create your script file, don't bother to add that funny first line, don't bother to chmod it then just run it with 'bash scriptname'.

Anyway, I added the semicolon at the end of the 'sleep' line and it's a bit better. At least it sleeps now!
Code:
[root@localhost asterisk]# cat wait.txt
sleep 10;
echo "Hello World"[root@localhost asterisk]# bash wait.txt
: command not found
Hello World
[root@localhost asterisk]#
altis is offline   Reply With Quote
Old 30-10-2006, 13:13   #6
The Jackal
Inactive
 
Join Date: Oct 2006
Posts: 1,604
The Jackal has a bronzed appealThe Jackal has a bronzed appeal
The Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appealThe Jackal has a bronzed appeal
Re: $ bash myscript

Quote:
Originally Posted by altis View Post
I don't know why Linux peeps like to make life so hard for themselves. There are at least two ways to run a script.
Heh
There are two types of ppl in this world my friend :

Those with guns

And those who dig.

----
Just pointing out the good the bad and the ugly wrt scripting.

Once you have hundreds of these scripts and want one to execute one with another and return the resultsets then you'll realise pretty sharpish if only i had put the stupid line at the start of my scripts i wouldn't be in this pickle.

Good programming practice too : shudders at the thought of code in a txt file : code in a text file what type of code is it ?

file <filename> would tell me straight away
file <yourfile> would say text file

More importantly how do you execute <yourfile> what if I use a different interpreter to bash say tclsh and in inadvertently a safe command in bash becomes an 'rm-rf /' in tclsh.

Your choice have fun coding.

---------- Post added at 12:13 ---------- Previous post was at 12:05 ----------

PS I'm not having a moan here just pointing out some best practices afterall I think its great you're doing some scripting
The Jackal is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:46.


Server: osmium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum